-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01_one.py
105 lines (87 loc) · 2 KB
/
01_one.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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
#in python everything is object
# strings
# chai = "lemon chai"
# print(chai)
# first_character= chai[0]
# print(first_character)
# string slicing
# slicing 'lemon chai' to 'lemon'
# slicing_chai = chai[0:5]
# print(slicing_chai)
# number_list= '0123456789'
# print(number_list[:])
# print(number_list[3:])
# print(number_list[:2])
# print(number_list[0:8:2]) # understand it as jumping on every 2nd tile
# # from where you are currently
# chai="Masala chai"
# print(chai.lower())
# print(chai.upper())
# stripping extra spaces, useful in web dev using python
# chai = " Masala chai "
# print(chai.strip())
# chai = "Lemon Chai"
# print(chai.replace("lemon", "Ginger"))
# converting string to list
# chai = "lemon, Ginger, Mint, Masala"
# # default spliter is "space" based
# print(chai.split(", "))
# # ['lemon', 'Ginger', 'Mint', 'Masala']
# chai = "Masala Chai"
# print(chai.find("Chai"))
# # 7
# if element does not exist return -1
# print(chai.find("chai"))
# -1
# chai = "Masala Chai Chai Chai"
# # counting no. of chai
# print(chai.count("Chai"))
# # 3
# # place holders in python
# chai_type = "Masala Chai"
# quantity = 2
# order = "I ordered {} {} cups of chai"
# print(order.format(chai_type, quantity))
# # I ordered Masala Chai 2 cups of chai
# # list to string
# chai_variety = ["Lemon Chai", "Ginger Chai", "Masala Chai"]
# print(chai_variety)
# print(", ".join(chai_variety))
# # String : Lemon Chai, Ginger Chai, Masala Chai
# # length of string
# chai = "Masala Chai"
# print(len(chai))
# # 11
# loop through string
# chai = "Masala Chai"
# for i in chai:
# print(i)
# # M
# # a
# # s
# # a
# # l
# # a
# #
# # C
# # h
# # a
# # i
# chai = "Masala chai is \"awsome.\""
# print(chai)
# # Masala chai is "awsome."
# chai = "Masala\nChai"
# print(chai)
# chai = r"Masala\nChai"
# print(chai)
# # Masala
# # Chai
# # Masala\nChai
# # path problem in python
# chai = r"c:\user:\hello\f"
# print(chai)
# # c:\\user:\\hello\\f
# # string containing
# chai = "Masala Chai"
# print("Masala" in chai)
# # True