-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpython01 (intro to python).py
52 lines (41 loc) · 1.53 KB
/
python01 (intro to python).py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Let's Start
# my first python programme -this is called comment.
# print-it is a command.
# "hello world"-it is string of text.
# print command displays a massage on the screen.
print ("hello world")
print ('I am Shawki')
""" this is a string. but we are not working with it.
so we are using it as a comment. this string like
comment is called documentation."""
# Python provides integrated support for embedding formal documentation directly
# in source code using a mechanism known as a docstring.
# it means, if we have documentation in the function or a class that is called docstring.
# and we can grab them by __doc__ attribute.
# how to count the number of characters in a string?
# using len function
# len is the short form of lenth
s="hello world"
print(len(s))
# how to find a characters with index
print(s[0])
# how to print hello from this variable.
print(s[0:5])
# this means print the characters from the beginning to the index 5 but not including index no 5.
# how to display a message with a place holder.
greeting="hello"
name="Shawki"
message="{}, {}. welcome!".format(greeting, name)
print(message)
# we can do the same thing using f strings.
greeting="hello"
name="Shawki"
message=f"{greeting}, {name}. welcome!"
print(message)
# how to display the methods that we can use in a string?
# using dir method.
print(dir(name))
# if we want to know lot more information about strings we can use help method.
print(help(str))# here str is the short form of string
# we can also search help for any function.
print(help(str.lower))