-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractpython2.py
More file actions
91 lines (74 loc) · 1.41 KB
/
practpython2.py
File metadata and controls
91 lines (74 loc) · 1.41 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
# is_old=False
# if is_old:
# print("you are old")
# else:
# print("not old")
# Ternary operator
'''
is_friend=False
can_message="message allowed" if is_friend else "not allowed"
print(can_message)
'''
#Short Circuiting
'''
is_friend=True
is_user=True
if is_friend and is_user:
print("Best friends forever")
'''
#for loop
'''
for i in 'anubhav':
print(i)
for i in [1,2,3,4]:
for j in 'anu':
print(i, j)
dict1={
'name': 'Anubhav',
'age':20,
'prof': 'agaga'
}
for key,value in dict1.items():
print(key,value)
for i in range(1,101):
print(i)
for i,char in enumerate(list(range(100))):
print(i+1,char)
'''
#functions
'''
def say_hello():
print('hello')
say_hello()
def say(name,emoji):
print(f'hello {name} {emoji}')
say('Anubhav',':)'
def super(*args,**kwargs):
total=0
for i in kwargs.values():
total+=i
print(args)
return sum(args),total
print(super(1,3,5,6,a=2,b=5))
'''
# start with local scope
# next check parent local scope
# check global scope
# check built in function
'''
def mul2(item):
return item*2
print(list(map(mul2,[1,4,53,3])))
'''
#list comprehension
# mylist=[char for char in 'anubhav']
# print(mylist)
#Set and dictionary comprehension
# mylist={char for char in 'anubhav'}
# print(mylist)
# simple_dict={
# 'a':1,
# 'b':2
# }
# mydict={key:value**2 for key,value in simple_dict.items()}
# print(mydict)