Back


1. Basic Arithmetic

• Addition
Input : 2+1
Output : 3

• Subtraction
Input : 2-1
Output : 1

• Multiplication
Input : 2*1
Output : 3

• Division
Input : 5/2
Output : 2.5

• Floor division
Input : 9 // 4
Output : 2

2. Variable Assignments

>>> a=7
>>> print(a)
7

>>> a=a+a
>>> print(a)
14

>>> a=a/7
>>> print(a)
2.0

>>> a=a-2
>>> print(a)
0.0

3. The names you use when creating these labels need to follow a few rules:

1. Names can not start with a number.
2. There can be no spaces in the name, use _ instead.
3. Can't use any of these symbols : '" , <> / ? | \ () ! @ # $ % ^ & * ~ - +
4. It's considered best practice  that names are lowercase.
5. Avoid using the characters 'l' (lowercase letter el), 'O' (uppercase letter oh), 
   or 'I' (uppercase letter eye) as single character variable names.
6. Avoid using words that have special meaning in Python like "list" and "str"

4. Determining variable type with type()

>>> a=6
>>> print(type(a))
<class 'int'>

>>> b=7.4
>>> print(type(b))
<class 'float'>

>>> c="hello world"
>>> print(type(c))
<class 'str'>

>>> d=[1,2,3]
>>> print(type(d))
<class 'list'>

>>> e=(1,2,3)
>>> print(type(e))
<class 'tuple'>

>>> f={1:"one",2:"two"}
>>> print(type(f))
<class 'dict'>

>>> g={1,2,3}
>>> print(type(g))
<class 'set'>

>>> h=True
>>> print(type(h))
<class 'bool'>

5. String Basics

>>> s='python_codes'
>>> print(s)
'python_codes'

>>> print(len(s))
12

>>> print(s[0])
'p'

>>> print(s[1:])
'ython_codes'

>>> print(s)
'python_codes'

>>> print(s[:7])
'python_'

>>> print(s[:])
'python_codes'

>>> print(s[::1])
'python_codes'

>>> print(s[::-1])
'sedoc_nohtyp'

>>> var = "a"
>>> print(var*10)
'aaaaaaaaaa'

>>> s=s+" python channel"
>>> print(s)
'python_codes python channel'

>>> s.upper()
'PYTHON_CODES PYTHON CHANNEL'

>>> s.lower()
'python_codes python channel'

>>> s.split('codes')
['python_', ' python channel']
Back