-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrevision.py
More file actions
153 lines (102 loc) · 2.13 KB
/
revision.py
File metadata and controls
153 lines (102 loc) · 2.13 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
"""name1 = "Aditi"
# list [2,3,4] collection
# tuple [2,3,5] fixed collection
# set {2,4} unique values
# dict {"a" : 1} key - value
name = "Python"
print(name[0])
print(name[1])
print("Hi " * 3)
name2 = input("Enter your name: ") # string by default
print(name2)
# flot to int
x = 5.9
print(int(x))
x = 5
y = "5"
print(x == y)
name = input("Enter name: ")
print("Hello", name)
x = int(input("Enter no: "))
print(x)
# exponent
print(2 ** 3)
for i in range(5):
print(i) # starts from 0 and stop before 5
for i in range(0, 10, 2):
print(i) # range(start , stop , step)
for i in range(0,10):
print(i) # range(start , stop)
for i in range(3):
for j in range(2):
print(i, j)
for i in range(5):
if i == 2:
continue
print(i)
# list
# Ordered
#Changeable (mutable)
#Allows duplicates
#Stores different data types
list = [1, "aditi", 3.3, True]
print(list)
print(list[1])
list[1] = "Nikita" # change value
list.append(5) # append at end
list.insert(0,"start")
print(list)
list.pop()
list.remove(1)
print(list)
nums = [10,20,30,40,50]
print(nums[1:4])
# string - Cannot change directly.
name = "python"
print(name.upper())
print(name.lower())
text = " hello "
print(text.strip()) # remove spaaces
text = "I like Java"
print(text.replace("Java", "Python"))
text = "apple mango banana"
print(text.split()) # convert string to list
words = ['I', 'love', 'Python']
print(" ".join(words)) # list to string
name = "Aditi"
age = 19
print(f"My name is {name} and age is {age}")
student = {
"name" : "Aditi",
"age" : 19
}
print(student)
student["branch"] = "Aids"
print(student)
for i in student:
print(i)
for j in student.values():
print(j)
for k,m in student.items():
print(k,m)
print(student.get("name"))
data = {
"student1": {
"name": "Aditi",
"age": 19
}
}
print(data["student1"]["name"])
# TUPLES immutable
a = (3,"Aditi",4.2)
print(a)
# sets - unique values, no indexing
s = {1,2,2,3,3}
print(s)"""
# functions
def greet(name):
print("hello",name)
greet("aditi")
def greet(name, name2):
print("hello",name, name2)
greet("aditi","nikita")