-
Notifications
You must be signed in to change notification settings - Fork 0
/
learnPython.py
104 lines (86 loc) · 1.86 KB
/
learnPython.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
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
print("Hi mom!")
print("This is me coding.")
# This is a single-lined comment in Python.
# When using the Python command line, type "exit()" to exit.
"""
This is a multi-line comment.
None of this code goes into execution.
"""
if 2 > 5:
print("Two is a biggest number than five.")
x = "John"
# is the same as
x = 'John'
"""
Here are some legal variable names:
myvar = "John"
my_var = "John"
_my_var = "John"
myVar = "John"
MYVAR = "John"
myvar2 = "John"
Here are some illegal variable names:
2myvar = "John"
my-var = "John"
my var = "John"
camelCaseVariable
PascalCaseVariable
snake_case_variable
"""
# Assigning Multiple Values
x, y, z = "Ex", "Why", "Zed"
a = b = c = "All the same value."
# Unpacking a Collection
fruits = ["apple", "banana", "cherry"]
x, y, z = fruits
print(x)
print(y)
print(z)
#~Data Types~
a = "Hi mom!" #str
b = 20 #int
c = 4.1 #float
#d = 1W #complex
e = ["This", "is a", "list."] #list
f = ("This", "is a", "list.") #tuple
g = range(100) #range
h = {"fact" : true} #dict
i = {"A list in curly", "brackets is a set."} #set
j = frozenset({"This", "is a", "frozenset data type."}) #frozenset
k = True #bool
l = b"String of bytes" # bytes
m = bytearray(5) #bytearray
n = memoryview(bytes(5)) #memoryview
o = None #NoneType
print(type(a))
print(type(b))
print(type(c))
#print(type(d))
print(type(e))
print(type(f))
print(type(g))
print(type(h))
print(type(i))
print(type(j))
print(type(k))
print(type(l))
print(type(m))
print(type(n))
print(type(o))
"""
x = "Python"
y = "is"
z = "awesome"
print(x, y, z)
is the same as
x = "Python "
y = "is "
z = "awesome"
print(x + y + z)
x = 5
x += 3 is also x = x = x + 3
"""
from datetime import datetime
now = datetime.now()
print '%02d-%02d-%04d %02d:%02d:%02d' % (now.month, now.day, now.year, now.hour, now.minute, now.second)
# These above lines should be able to tell the time.