3. Determining variable type with type()
>> a=7
>>> type(a)
<class 'int'>
>>> b=7.7
>>> type(b)
<class 'float'>
>>> c="hello"
>>> type(c)
<class 'str'>
>>> d=[1,2,3]
>>> type(d)
<class 'list'>
>>> e=(1,2,3)
>>> type(e)
<class 'tuple'>
>>> f={1:"one",2:"two"}
>>> type(f)
<class 'dict'>
>>> g={1,2,3}
>>> type(g)
<class 'set'>
>>> i=True
>>> type(i)
<class 'bool'>
You can check what type of object is assigned to a variable using Python's built-in type() function. Common data types include:
int (for integer)
float
str (for string)
list
tuple
dict (for dictionary)
set
bool (for Boolean True/False)
@python_codes
>> a=7
>>> type(a)
<class 'int'>
>>> b=7.7
>>> type(b)
<class 'float'>
>>> c="hello"
>>> type(c)
<class 'str'>
>>> d=[1,2,3]
>>> type(d)
<class 'list'>
>>> e=(1,2,3)
>>> type(e)
<class 'tuple'>
>>> f={1:"one",2:"two"}
>>> type(f)
<class 'dict'>
>>> g={1,2,3}
>>> type(g)
<class 'set'>
>>> i=True
>>> type(i)
<class 'bool'>
You can check what type of object is assigned to a variable using Python's built-in type() function. Common data types include:
int (for integer)
float
str (for string)
list
tuple
dict (for dictionary)
set
bool (for Boolean True/False)
@python_codes
4. String Basics
>>> s='python_codes'
>>> s
'python_codes'
>>> len(s)
12
>>> s[0]
'p'
>>> s[1:]
'ython_codes'
>>> s
'python_codes'
>>> s[:7]
'python_'
>>> s[:]
'python_codes'
>>> s[::1]
'python_codes'
>>> s[::-1]
'sedoc_nohtyp'
>>> var = "a"
>>> var*10
'aaaaaaaaaa'
>>> s=s+" python channel"
>>> s
'python_codes python channel'
>>> s.upper()
'PYTHON_CODES PYTHON CHANNEL'
>>> s.lower()
'python_codes python channel'
>>> s.split('codes')
['python_', ' python channel']
@python_codes
>>> s='python_codes'
>>> s
'python_codes'
>>> len(s)
12
>>> s[0]
'p'
>>> s[1:]
'ython_codes'
>>> s
'python_codes'
>>> s[:7]
'python_'
>>> s[:]
'python_codes'
>>> s[::1]
'python_codes'
>>> s[::-1]
'sedoc_nohtyp'
>>> var = "a"
>>> var*10
'aaaaaaaaaa'
>>> s=s+" python channel"
>>> s
'python_codes python channel'
>>> s.upper()
'PYTHON_CODES PYTHON CHANNEL'
>>> s.lower()
'python_codes python channel'
>>> s.split('codes')
['python_', ' python channel']
@python_codes
5. Lists
>>> list=[8,0,5,1]
>>> list
[8, 0, 5, 1]
>>> len(list)
4
>>> list_2=['string',8086,'p']
>>> list_2
['string', 8086, 'p']
>>> len(list_2)
3
Indexing and Slicing
>>> list=['one','ox','ok']
>>> list[0]
'one'
>>> list[1:]
['ox', 'ok']
>>> list[:2]
['one', 'ox']
>>> list[-1]
'ok'
>>> list[::-1]
['ok', 'ox', 'one']
>>> list+[235]
['one', 'ox', 'ok', 235]
>>> list*2
['one', 'ox', 'ok', 'one', 'ox', 'ok']
Basic List Methods
>>> list=[4,0,1,3]
>>> list.append("new")
>>> list
[4, 0, 1, 3, 'new']
>>> list.pop(0)
4
>>> list
[0, 1, 3, 'new']
>>> list.reverse()
>>> list
['new', 3, 1, 0]
Nesting Lists
>>> lst_1=[1,2,3]
>>> lst_2=[4,5,6]
>>> lst_3=[7,8,9]
>>> matrix = [lst_1,lst_2,lst_3]
>>> matrix
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
>>> matrix[1]
[4, 5, 6]
>>> matrix[0][1]
2
@python_codes
>>> list=[8,0,5,1]
>>> list
[8, 0, 5, 1]
>>> len(list)
4
>>> list_2=['string',8086,'p']
>>> list_2
['string', 8086, 'p']
>>> len(list_2)
3
Indexing and Slicing
>>> list=['one','ox','ok']
>>> list[0]
'one'
>>> list[1:]
['ox', 'ok']
>>> list[:2]
['one', 'ox']
>>> list[-1]
'ok'
>>> list[::-1]
['ok', 'ox', 'one']
>>> list+[235]
['one', 'ox', 'ok', 235]
>>> list*2
['one', 'ox', 'ok', 'one', 'ox', 'ok']
Basic List Methods
>>> list=[4,0,1,3]
>>> list.append("new")
>>> list
[4, 0, 1, 3, 'new']
>>> list.pop(0)
4
>>> list
[0, 1, 3, 'new']
>>> list.reverse()
>>> list
['new', 3, 1, 0]
Nesting Lists
>>> lst_1=[1,2,3]
>>> lst_2=[4,5,6]
>>> lst_3=[7,8,9]
>>> matrix = [lst_1,lst_2,lst_3]
>>> matrix
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
>>> matrix[1]
[4, 5, 6]
>>> matrix[0][1]
2
@python_codes
6. Conditionals
example
x = 5
if x == 5:
print("x equals 5")
else:
print("x does not equal 5")
it will output
x equals 5
🍏 other operators
x = 6
if x > 5:
print("x greater than 5")
else:
print("x less than 5")
outputs
x greater than 5
other operators
< less than
!= not equal to
>= greater equal to
<= less equal to
smart python
if 3<x<5:
means if x between 3 and 5
@python_codes
example
x = 5
if x == 5:
print("x equals 5")
else:
print("x does not equal 5")
it will output
x equals 5
🍏 other operators
x = 6
if x > 5:
print("x greater than 5")
else:
print("x less than 5")
outputs
x greater than 5
other operators
< less than
!= not equal to
>= greater equal to
<= less equal to
smart python
if 3<x<5:
means if x between 3 and 5
@python_codes
from turtle import *
color('red', 'green')
begin_fill()
while True:
forward(200)
left(170)
if abs(pos()) < 1:
break
end_fill()
done()
@python_codes
color('red', 'green')
begin_fill()
while True:
forward(200)
left(170)
if abs(pos()) < 1:
break
end_fill()
done()
@python_codes
AI_ML.pdf
324.4 KB
What is the difference between Artificial Intelligence and Machine Learning ?