-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython6.py
More file actions
85 lines (58 loc) · 1.47 KB
/
Copy pathpython6.py
File metadata and controls
85 lines (58 loc) · 1.47 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
# python 6: sets, dictionary, index-operator, functions,arguments
#set (no duplicate value)
utencils = {"spoon", "knife", "plates", "fork"}
dishes = {"bowl", "plate", "cup","knife"}
utencils.add("napkin")
dinner_table = utencils.union(dishes)
for x in dinner_table:
print(x)
# dictionary : allow us to quickly change a value
# 1
capitals = {'USA': 'Washington DC',
'INDIA': 'New Delhi',
"France": "Paris",
'CHINA': 'Beijing'}
print(capitals['INDIA'])
del capitals["USA"] # removes USA
print(capitals.items())
for key,value in capitals.items():
print(key,value)
# 2
user = {
"username": "alia23",
"password": "123@alia",
"age": 17
}
print(user["username"]) # alia23
print(user["age"]) # 17
# index operator give access to sequence's elements
name = "Spong bob"
first = name[:6].lower()
last_chr = name[-1]
print(first)
print(last_chr)
# functions
# 1
def hello( ):
print("HELLO!")
print("You are in function")
hello()
# 2
def hello(name):
print("HELLO! " +name)
print("You are in function")
hello("Bro")
# 3
def add(a, b):
return a + b
result = add(3, 5)
print(result)
# return statement
def add(number1,number2):
return number1 + number2
x = add(3,6)
print(x)
# arguments
def hello(first,middle,last):
print("Hello! " +first+ " " +middle+ " " +last+" " )
hello(first="Spong",middle="Bob",last="mike")