-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintro.py
53 lines (40 loc) · 1.04 KB
/
intro.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
# Ben's intro to Python
# numbers!
age = 26
#why are these different output?
print(age/5)
print(age/5.0)
pi = 3.14159
avagadro = 6.02214E23
# strings!
s = 'Thomas Henry Huxley'
names = s.split()
#split is a string function, what does it return?
first_name = names[0]
middle_name = names[1]
last_name = names[2]
s2 = first_name + ' ' + middle_name + ' ' + last_name
# 'if' statement - indentation matters!
if (s == s2):
print('yes!!!')
else:
print('nooooooo')
# list (ordered sequence)
beatles = ['John', 'Paul', 'George', 'Pete', 'Stuart']
len(beatles)
beatles.pop()
beatles.pop()
beatles.append('Ringo')
led_zeppelin = ["Jimmy", "Robert", "John", "John"]
# 'for' loop - indentation matters!
for b in beatles:
print('Hello ' + b)
# set (no order, no duplicates)
unique_zeppelin = set(led_zeppelin)
unique_beatles = set(beatles)
#which members are shared between the two?
shared = unique_zeppelin.intersection(unique_beatles)
print(shared)
# no guaranteed order when iterating over a set
for beatle in unique_beatles:
print(beatle)