1+ # DataTypes
2+
3+ print (type ("Hello World" ))
4+ print ()
5+
6+ # Type function give the type of the data stored
7+
8+ var1 = "41"
9+ var2 = "57"
10+
11+ print (var1 + var2 )
12+
13+ # Addition of two strings concatinate them
14+
15+ print (int (var1 ) + int (var2 ))
16+
17+ # Int() function can change any data type into integer if possible
18+
19+ """
20+ Similarly, we have :
21+
22+ str()
23+ float()
24+
25+ """
26+
27+ # we could also multiply the number in int statement
28+
29+ print (2 * int (var1 ) + int (var2 ))
30+
31+
32+
33+ # Strings
34+
35+ mystr = "Hello World"
36+
37+ print (len (mystr ))
38+ print ()
39+
40+ # len() gives the length of the string (no. of characters)
41+
42+
43+ """ String Slicing """
44+
45+ print (mystr [0 ])
46+
47+ # If we want a particular character of the string we can write the place of character in a big bracket after string name
48+
49+ # In programming number starts from 0
50+
51+ print (mystr [0 :5 ])
52+
53+ # This is used when we want a particular part to the string by using : between the start and end character
54+
55+ # The upper valuse in included but lower value in excluded
56+
57+ print (mystr [0 :11 :2 ])
58+
59+ # The the second : represents the no of characters to be skipped
60+
61+ # 2 means it only shows every second character after the previous one
62+
63+
64+ """ Blanks """
65+
66+ print (mystr [8 :])
67+
68+ # Leaving any space blank will take the extreme position of it
69+
70+ # Example
71+
72+ print (mystr [ :11 ])
73+
74+ # Blank was taken as 0
75+
76+ print (mystr [ : : ])
77+
78+ # Leaving second : blank will take is as 1
79+
80+
81+ """ Negatives """
82+
83+ print (mystr [- 8 :- 1 ])
84+
85+ # - reprents the counting from the last
86+
87+ # -0 doesn't exist so the number here satrt from -1
88+
89+ print (mystr [ : : - 1 ])
90+ print ()
91+ # Taking the number after second : in negative will reverse the string
92+
93+
94+ """ Functions """
95+
96+ print (mystr .isnumeric ())
97+ print ()
98+
99+ # .isnumeric() tells us whether the string is numeric or not
100+
101+ # Is is a Boolean datatype so, it answers only in true and false
102+
103+ """
104+ Similarly, we have
105+
106+ .isalpha()
107+ # Check about alphanumeric
108+
109+ .endswith()
110+ # Check where it ends with given characters
111+
112+ .count()
113+ # Count the number of characters
114+
115+ .capitalize()
116+ # Capitalise the first letter
117+
118+ .find()
119+ # Find the position of the characters
120+
121+ .lower()
122+ # Decapitalise the whole string
123+
124+ .upper()
125+ # Capitalise the whole string
126+
127+ .replace("" , "")
128+ # Take two arguments 1. to replace 2. with what
129+
130+ """
131+
132+ params = mystr .split (" " )
133+ print (params )
134+ print ()
135+
136+ # .split() takes one arguement and splits the string into different part according to arguements and make a list out of it
137+
138+
139+ """ F strings """
140+
141+ a = "Harsh"
142+ print ("This is %s" % a )
143+
144+ # %s represents the place where we want to add variable
145+
146+ # After the string %variable inserts the value
147+
148+ # This is suitable for few variables but not for a huge amount
149+
150+ print (f"This is { a } " )
151+ print ()
152+
153+ # Writting f before string makes it f string
154+
155+ # Use of { } inside the f string to specify the variables in the space
156+
157+ # We could also give any operation inside f string
158+
159+
160+ """ Raw String """
161+
162+ print (r"\n This is a raw string" )
163+
164+ # raw string is made using r before " "
165+
166+ # raw string behave like a string without any escape sequence character and variable names
0 commit comments