Roshan Book

My Tech Notebook

Tag Archives: tuple

Python tutorial 6 lists and its methods

# List

# List Methods
# For the list
cast = [“Cleese”, “Palin”, “Jones”, “Idle”]
print (cast)

# finding length
print (len(cast))

# Print specific position value
print (cast[3])

# Append – adds to last of the list
print (cast)

# Pop- remove last item


# Extend – adds multiple items at the end
cast.extend([“Gilliam”, “Chapman”])

# Remove – remove specific data


# Insert data to specific postion
cast.insert (0,”Chapman”)


Iterate (moving along each item) along list

fav_movies =[“manish”, “roshan”, “is”]

for each_item in fav_movies:


# List inside list

movies=[“Tere Naam”, Hindi[“Marigold”, “Indian”]]

accessing value – print (movies[1][0])- output Marigold

Python tutorial 5 Variables Objects and Values

Everything in python is an object

All object has an ID, Type and Value

Mutable object change values – Lists, dictionaries

Immutable object does not change values – numbers, strings, tuples

# Checking ID, Value and Type of a variable

>>> x =42
>>> id(x)
>>> type(x)
<class ‘int’>

# Numbers

int and float

num=42//9 , gives integer answer and not rounded up – 4

num = round(42/9, 2) – round to 2 places of decimal- 5

num= 42%9 – reminder 6

# Strings

print (r“this is n string”) – adding r removes any backslash effect and print n as it is

Printing variable

s=”This is a {} string”.format(n)

format is a method in string object

‘’’ ‘’’ – triple quotes helps to print multiple lines


x=(1,2,3) – immutable . you cannot append things



x= [1,2,3] – mutable. You can add, change, delete in Lists

# Dictionary

x = {‘one’:1, ‘two’:2}

x==y compare their values

x is y -check if id is same

%d bloggers like this: