Repository navigation
Expand file tree
/
Copy pathString Format and operators Intro.py
More file actions
92 lines (67 loc) · 2 KB
/
Copy pathString Format and operators Intro.py
File metadata and controls
92 lines (67 loc) · 2 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#--- String in python-------
#--String is written in single and double and triple quotes--
name = "Ankit" #---Creating a string----
print(name)
#---Type checking----
print(type("Ankit"))
print('Ankit') #---single quote--
print("Won't allow")
print("Ankit") #---Double quotes---
print(''' "kw-double-Quotes" ''') #--want string with double quote--
print(" \"my world\" ")
#--Formatted string---
#--1=old style formatting , %-operator
name = "Ankit"
age = 20
print("my name is %s and %d" % (name, age)) #--%s and %D are the placeholders for string anh int
#--2-- str.format mrthod---
name = "Ankit"
age = 20
print("my name is {} and {}".format (name, age)) #--%s and %D are the placeholders for string anh int
#---wih refrence---
name = "Ankit"
age = 20
print("my name is {0} and {1}".format (name, age)) #--%s and %D are the placeholders for string anh int
name = "Ankit"
age = 20
print("my name is {1} and {0}".format (name, age)) #--%s and %D are the placeholders for string anh int
name = "Ankit"
age = 20
print("my name is {name} and {age}".format (name="Madhav", age=24)) #--%s and %D are the placeholders for string anh int
#--3--f-strings---
name = "Ankit"
age = 35
print(f"{name} {age}")
name = "Ankit"
age = 35
print(f"{name} {age+5}") # can add value in int--
#--Escape characters--- backslash(\) with chars
print(''' "kw-double-Quotes" ''') #--want string with double quote--
print(" \"my world\" ")
print(" \'my world\' ")
print(" my \n world ")
print(" hello\tworld ")
#---String operators----
a = "Hello"
b = "Python"
print(a+b) #--Concatinate
print(a*2) #--mutiple copies
#---MEMBERSHIP
a = "Hello"
b = "Python"
if "H" in a:
print("yes")
else:
print("no")
#---Membership==
a = "Hello"
b = "Python"
if "H" not in a:
print("yes")
else:
print("no")
print("Hello\nworld")
print(r"Hello\nworld") #--raw string---
name= "Hello"#---%--string---
name1 = 34
print("the a %s and %d" % (name, name1))