-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStringFormat.py
More file actions
50 lines (40 loc) · 916 Bytes
/
Copy pathStringFormat.py
File metadata and controls
50 lines (40 loc) · 916 Bytes
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
n1 = 10
n2 = 20
name = "maria"
id = 106
print(f"My name is {name} and my id is {id}")
print(f"Calculation by formatting: {n1+n2:.2f}\n")
# single line comment
print("Hello world")
print(420)
''' multi line
comment'''
name = "maria"
id1 = 106
id2 = 364.0
print(name, id1, id2, "\n")
# upper & lower case
s = "Hello World"
print(s.upper())
print(s.lower())
# remove space at begining
m = " Maria"
print(m)
print(m.strip())
print("After replacing:", m.replace("M", "N"), "\n")
# string slicing
name = "Maria"
slicing = name[0:3] # start from 0 till 3 [excluding 3]
print(slicing)
print(name[-4:-1]) # same as [1:4]
print(name[:4])
print(name[1:]) # same as [1:5]
# string slicing with skip value
a = "0123456789"
print(a[1:8])
print(a[1:8:2], "\n")
# String function
name = "zannatul"
print(len(name))
print(name.endswith("tul"))
print(name.capitalize())