-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_practice_5.py
More file actions
58 lines (46 loc) · 852 Bytes
/
python_practice_5.py
File metadata and controls
58 lines (46 loc) · 852 Bytes
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
#Functions:
def say_hello():
print('Hello')
say_hello()
print(say_hello()) #This will return the location of say_hello().
#Arguments vs Parameters:
def say_hello(name,emoji):
return f'Hello {name} {emoji}.'
print(say_hello('Keshav','😁'))
def test(a):
'''
Info: This function tests and prints parameter a
'''
print(a)
test('!!!')
help(test)
#Walrus operator:
a="helloooooooooo"
if ((n:=len(a))):
print(f"Too long {n} elements.")
#Scope : What variables do i have access to ?
'''
b=1
def parent():
b=10
def confusion():
return b
print(parent())
print(b)
#Global Keyword:
a=10
def func():
global a
print(a)
func()
'''
#Non-local keyword:
def outer():
x='local'
def inner():
nonlocal x
x='nonlocal'
print("inner:",x)
inner()
print("outer:",x)
outer()