*www.codingdojo.com (on indeed.com listings)
**            >>>   Exponent                    >>>  2 ** 3 = 8
% >>> Modulus/Remainder >>> 22 % 8 = 6
// >>> Integer division >>> 22 // 8 = 2
/ >>> Division >>> 22 / 8 = 2.75
* >>> Multiplication >>> 3 * 3 = 9
- >>> Subtraction >>> 5 - 2 = 3
+ >>> ADITTION >>> 22 + 8 = 30

## Examples of expressions in the interactive shell:

>>> 2 + 3 * 6
20
>>> (2 + 3) * 6
30
>>> 23 % 7
2
>>> (5 - 1) * ((7 + 1) / (3 - 1))
16.0
>>> 3-3
0
>>> 3/3
1
>>> 3*3
9
>>> 3**3
27

String Concatenation and Replication

String concatenation:

>> 'Alice' 'Bob' 
'AliceBob'
>>> 'Alice' * 5
'AliceAliceAliceAliceAlice'

Variables

You can name a variable anything as long as it obeys the following rules:

  1. It can be only one word.
  2. It can use only letters, numbers, and the underscore (_) character.
  3. It can’t begin with a number.
>>> spam = ‘Hello’
>>> spam
‘Hello’

The print() Function

>>> print('Hello world!')
Hello world!

The input() Function

>>> print('What is your name?')   # ask for their name
>>> myName = input()
>>> print('It is good to meet you, {}'.format(myName))
What is your name?
Al
It is good to meet you, Al

The len() Function

Evaluates to the integer value of the number of characters in a string:

>>> len('hello')
5
>>> a = [1, 2, 3] 
>>> if a:
>>> print("the list is not empty!")

The str(), int(), and float() Functions

integer to String or Float

>>> str(29)
'29'
>>> print('I am {} years old.'.format(str(29)))
I am 29 years old.
>>> str(-3.14)
'-3.14'
>>> int(7.7)
7
>>> int(7.7) + 1
8

Flow Control

Comparison Operators

>>> 42 == 42
True
>>> 40 == 42
False
>>> 'hello' == 'hello'
True
>>> 'hello' == 'Hello'
False
>>> 'dog' != 'cat' #not equal to
True
>>> 42 == 42.0
True
>>> 42 == '42'
False

Boolean evaluation

Use the is or is not operators, or use implicit boolean evaluation.

>>> True is True
True
>>> True is not False
True
###These statements are equivalent:>>> if a is True:
>>> pass
>>> if a is not False:
>>> pass
>>> if a:
>>> pass

Mixing Boolean and Comparison Operators

>>> (4 < 5) and (5 < 6)
True
>>> (4 < 5) and (9 < 6)
False
>>> (1 == 2) or (2 == 2)
True
##You can also use multiple Boolean operators in an expression, along with the comparison operators:>>> 2 + 2 == 4 and not 2 + 2 == 5 and 2 * 2 == 2 + 2
True

if Statements

if name == 'Alice':     
print('Hi, Alice.')

else Statements

name = 'Bob'
if name == 'Alice':
print('Hi, Alice.')
else:
print('Hello, stranger.')

elif Statements

name = 'Bob'
age = 5
if name == 'Alice':
print('Hi, Alice.')
elif age < 12:
print('You are not Alice, kiddo.')
name = 'Bob'
age = 30
if name == 'Alice':
print('Hi, Alice.')
elif age < 12:
print('You are not Alice, kiddo.')
else:
print('You are neither Alice nor a little kid.')

while Loop Statements

spam = 0
while spam < 5:
print('Hello, world.')
spam = spam + 1

break Statements

If the execution reaches a break statement, it immediately exits the while loop’s clause:

while True:
print('Please type your name.')
name = input()
if name == 'your name':
break
print('Thank you!')

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store