1+ #number in python
2+ #data type of number in python
3+ int_num = 10
4+ float_num = 10.5
5+ complex_num = 2 + 3j
6+ print ("type of " ,int_num , "is" , type (int_num ))
7+ print ("type of " ,float_num , "is" , type (float_num ))
8+ print ("type of " ,complex_num , "is" , type (complex_num ))
9+
10+ import random
11+ print (random .randint (1 , 100 )) # to generate a random number between 1 and 100
12+
13+ suman Bishwakarma
14+ 20 :52
15+ screen off vayo
16+
17+ SAUGAT
18+ 20 :59
19+ # string in python
20+ name = "saugat"
21+ print ("name:" , name )
22+ print ("type of name:" , type (name ))
23+ print ("character at index 0:" , name [0 ])
24+ print ("length of name:" , len (name ))
25+
26+ decription = """
27+ this is a multi line string
28+ we can use triple quotes to create a multi line string
29+ this is the end of the multi line string
30+ """
31+
32+ print ("description:" , decription )
33+ concatination = name + " is a teacher"
34+ print ("concatination:" , concatination )
35+ print ("index 1 of description:" , decription [1 ])
36+
37+
38+ #is smth in description
39+ print ("saugat " in decription )# false
40+ print ("saugat " not in decription )# true
41+
42+ # string methods
43+ print ("name in uppercase:" , name .upper ())
44+ print ("name in lowercase:" , name .lower ())
45+ print (dir (name )) # to see all the methods of string
46+ #capitalize the first letter of the string
47+ print ("name with capitalized first letter:" , name .capitalize ())# first letter of the string will be capitalized and the rest will be in lowercase
48+ print ("name with capitalized first letter:" , name .title ()) # to capitalize the first letter of each word in the string
49+
50+ sentence = " this is a sentence with leading and trailing spaces "
51+ print ("sentence with leading and trailing spaces:" , sentence .strip ()) # to remove leading and trailing spaces from the string
52+
53+ list_of_words = "apple, banana, orange"
54+ print ("list of words:" , list_of_words .split (", " )) # to split the string into a list of words based on the delimiter ", "
55+ #replace
56+ print ("name with replaced characters:" , name .replace ("s" , "R" )) # to replace all occurrences of "a" with "o" in the string
57+
58+ #index
59+ print ("index of a in name:" , name .index ("a" )) # to find the index of the first occurrence of "a" in the string
0 commit comments