xxxxxxxxxx
# Python range mathods
for i in range(5):
# This will run inner content 5 times
print("Print this 5 times")
# range(starting value, ending value, steps)
for i in range(5,11,2):
print(i)
# Output-> 5,7,9
xxxxxxxxxx
# Syntax - range(start, stop, step) - you must use integers, floats cannot be used
for i in range(3):
print(i)
# output - automatically taken start = 0 and step = 1, we have given stop = 3 (excluding 3)
for i in range(0, 4):
print(i)
# output - We have given start = 0 and stop = 4 (excluding 4), automatically taken step =1
for i in range(0, 5, 2):
print(i)
# output - We have given start = 0, stop = 5 (excluding 5), step = 2
for i in range(0, -4, -1):
print(i)
# output - We can go even backwards and also to negative numbers
xxxxxxxxxx
for i in range(start, end):
dosomething()
#The i is an iteration variable that you can replace by anytthing. You do not need to define it.
xxxxxxxxxx
# i start from 0 going to 4 "5 steps"
for i in range(5):
print(i)
# output
0
1
2
3
4
xxxxxxxxxx
#Python range() example
print("Numbers from range 0 to 6")
for i in range(6):
print(i, end=', ')
xxxxxxxxxx
for x in range(0, 10):
print(x)
#this is used similarly as the for(var i =0; i<x.length)... in some other languages*/
xxxxxxxxxx
for i in range(5):
print(i)
"""
0
1
2
3
4
"""
for i in range(5, 10):
print(i)
"""
5
6
7
8
9
"""
for i in range(5, 15, 3):
print(i)
"""
5
8
11
14
"""
xxxxxxxxxx
Command: dict()
What is dict: Dictionary Constructor Function
Description: The dict() function creates a new dictionary object, optionally from a list of key-value pairs.
Example: new_dict = dict([('a', 1), ('b', 2)]) will create a dictionary {'a': 1, 'b': 2}.