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
# Integer Variable | |
intVariable = 1 | |
# Float Variable | |
floatVariable = 1.5 | |
# String Variable | |
stringVariable = "hello world" | |
# Boolean Variable |
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
intVariable = 1 | |
print(intVariable) # will print out the value intVariable is assigned to which is 1 |
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
# If Statements | |
if True: | |
print("The If statement is True") | |
if 2 > 1: | |
print("2 is greater than 1") | |
# Else Statements | |
if 2 < 1: |
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
myList = [1, 2, 3, 4, 5] | |
# List Appending | |
myList.append(6) | |
print(myList) # Result: [1, 2, 3, 4, 5, 6] | |
# Removing an element | |
myList.remove(2) | |
print(myList) # Result: [1, 3, 4, 5, 6] |
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
myTuple1 = (1, 2, 3, 4, 5) | |
myTuple2 = ('a', 1, 'b', 2, 'c', 3') | |
# Indexing | |
print(myTuple1[2]) # Result is 3 | |
# Range Indexing | |
print(myTuple1[2:4]) # Result is (3, 4) |
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
mySet = {'a', 'b', 'c'} | |
# Adding to the set | |
mySet.add('d') | |
print(mySet) # Sets are unordered so the resulting Set varies | |
# An example of a result would be {'a', 'd', 'b', 'c'} | |
# Removing from the set | |
mySet.remove('c') |
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
myDictionary = { | |
'a': 1, | |
'b': 2, | |
'c': 3 | |
} | |
# Keys are: 'a', 'b', 'c' | |
# Values are: 1, 2, 3 | |
# Can get the value of a specific key in 2 ways |
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
myList = [1, 2, 3, 4, 5] | |
# Iterating through a list | |
for i in myList: | |
print(i) # The elements in myList will each get printed on a new line | |
for i in range(len(myList)): | |
print(myList[i]) # Same thing, but the elements are getting index and then printed out | |
# Iterating through a string |
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
incrementer = 1 | |
while incrementer < 6: | |
print(incrementer) | |
incrementer = incrementer + 1 # re-assigning incrementer to one value higher | |
# while loop breaks when incrementer equals 6 | |
# the while loop runs 5 times and | |
# 1, 2, 3, 4, and 5 are printed on 5 lines |
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
def hello(): | |
return("Hello") | |
print(hello()) # printing the call of the function which returns "Hello" | |
def name(firstName, lastName): | |
return("Hello, my name is " + firstName + " " + lastName) | |
print(name("John", "Doe")) # name function gets called |
OlderNewer