Last active
July 18, 2019 22:43
-
-
Save abelcallejo/ac7438f7bba24e6295d5443bb3be0892 to your computer and use it in GitHub Desktop.
Crash course on Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
print(sys.argv[0]) # CommandLineArguments.py | |
print(sys.argv[1]) # hello | |
print(sys.argv[2]) # world | |
#python CommandLineArguments.py hello world |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#print("Hello world") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("Hello world") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# basic arithmetic operators | |
six = 4 + 2 # addition | |
two = 4 - 2 # subtraction | |
eight = 4 * 2 # multiplication | |
four = 8 / 2 # division | |
# intermediate arithmetic operators | |
nine = 3 ** 2 # exponent | |
one = 9 % 2 # modulus | |
three = 23 // 7 # floor division; opposite of modulus | |
# boolean operators (returns boolean) | |
a = True & False # and | |
b = True | False # or | |
c = False ^ True # xor | |
d = not True # negate | |
# comparison operators (returns boolean) | |
e = 5 == 0 # is equal to 0 | |
f = 5 != 0 # is not equal to | |
g = 5 <> 0 # is not equal to | |
h = 5 > 0 # is greater than | |
i = 0 < 5 # is lesser than | |
j = 5 >= 0 # is greater than or equal to | |
k = 0 <= 5 # is lesser than or equal to | |
# output | |
print(six) # 6 | |
print(two) # 2 | |
print(eight) # 8 | |
print(four) # 4 | |
print(nine) # 9 | |
print(one) # 1 | |
print(three) # 3 | |
print(a) # False | |
print(b) # True | |
print(c) # True | |
print(d) # False | |
print(e) # False | |
print(f) # True | |
print(g) # True | |
print(h) # True | |
print(i) # True | |
print(j) # True | |
print(k) # True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = "Hello world" | |
print(a[0]) # prints "H" | |
print(a[0:1]) # prints "H" | |
print(a[0:2]) # prints "He" | |
print(a[0:3]) # prints "Hel" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# integers | |
x = int(1) # x will be 1 | |
y = int(2.8) # y will be 2 | |
z = int("3") # z will be 3 | |
# floats | |
x = float(1) # x will be 1.0 | |
y = float(2.8) # y will be 2.8 | |
z = float("3") # z will be 3.0 | |
w = float("4.2") # w will be 4.2 | |
# strings | |
x = str("s1") # x will be 's1' | |
y = str(2) # y will be '2' | |
z = str(3.0) # z will be '3.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# numeric | |
int_variable = 5 | |
float_variable = 2.8 | |
complex_variable = 5j | |
# string | |
string_variable = "This works" | |
string_variable = 'This works too' | |
# boolean | |
boolean_variable = True | |
boolean_variable = False | |
# output | |
print(int_variable) | |
print(float_variable) | |
print(complex_variable) | |
print(string_variable) | |
print(boolean_variable) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment