Folder full of pertinent coursework
Kernel: Python 2
Jupyter Task 3
Sidy Danioko
Sean Paradiso
Python Syntax
- Comments in python are anything preceeded by a '#'
In [ ]:
- Declaring a variable does not require a type
In [7]:
- The syntax for printing output is print("string1" + "string2")
In [8]:
Out[8]:
5
Sean
Python Data Types
- The boolean data type is a binary taking True and/or False
In [16]:
Out[16]:
They are different
- The integer data type is a primitive data type used for integers
In [18]:
Out[18]:
int
- The float data type is a primitive data type used for real numbers
In [21]:
Out[21]:
2.42307692308
float
- The string data type is a primitive data type used for an array of characters
In [22]:
Out[22]:
Sean Paradiso
str
- The list data type is a primitive data type used for a collection of items of the same or different types in a specific order
In [40]:
Out[40]:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
0
1
100
[0, 1, 100, 3, 4, 5, 6, 7, 8, 9]
list
- The tuple data type is an immutable ordered list
In [32]:
Out[32]:
File "<ipython-input-32-6ef0b3d75e39>", line 6
myTup(0) = 30
SyntaxError: can't assign to function call
- The dictionary data type is a key-value system
In [39]:
Out[39]:
{'Dad': 90, 'Brother': 50, 'Mom': 100}
Dad
Brother
Mom
90
50
100
dict
- The set data type is similar to a list with the exception of not allowing duplicates
In [46]:
Out[46]:
set([1, 2, 3, 4, 5])
set([1, 2, 3, 4, 5, 8, 'You the man'])
set
Python Control Structures
- The syntax for an if-then-else control structure is used by initiating with the key word "if" followed by a test
In [53]:
Out[53]:
Please enter an integer: 5
a is an odd number
Please enter your first name :sdivhjsldivilsdj
Your name is too long
- The syntax for a for loop control structure is used by initiating with the key word "for" which will iterrate through a list. (This means the final value within the given range is the stopping condition and will not be evaluated)
In [55]:
Out[55]:
1
4
9
16
25
36
49
64
81
- The syntax for a for while control structure is used by initiating with the key word "while" which will iterrate through a list until a condition is no longer met. (This means the final value within the given range is the stopping condition and will not be evaluated)
In [63]:
Out[63]:
Please a give me a name or type x to exit: 5
Keep going
Please a give me a name or type x to exit: x
Python Organizational Structures
- The syntax for defining a function with a name as an organizational structure creates a new function through the use of the key word "def" and returns a value with a return statement
In [8]:
Out[8]:
x is 12 and y is 4
8
- The syntax for including a docstring is an indented block surrounded by quotes
In [9]:
Out[9]:
x is 12 and y is 4
8
- The syntax for *args is a list in which superfluous arguments are placed
In [26]:
Out[26]:
('apples',)
('apples', 'chicke', 'rice')
- The syntax for **kwargs is taking additional arguments and places them in a dictionary with a title of your choosing. This title can be anything as long as it is preceeded by two asterisks (in this example we have **kwargs)
In [57]:
Out[57]:
Dad is 100 years old
Mom is 90 years old
('a', 10)
('c', 100)
('b', -3)