Here is the python for loop example code
cars= ["BMW", "AUDI", "TESLA"]
for x in cars :
print(x)
Here is the python for loop example2
for x in "python": print(x)
OutPut:
p
y
t
h
o
n
Tutorialshore
Here is the python for loop example code
cars= ["BMW", "AUDI", "TESLA"]
for x in cars :
print(x)
Here is the python for loop example2
for x in "python": print(x)
OutPut:
p
y
t
h
o
n
To get the last value in an list using python is a very simple ,we can use Negative indexes , it is the index from the end of the List.
arr_even = [2, 4, 6, 8, 10, 12, 14 ,16 ,18]
print(arr_even[-1])
Output 18
we know that function has rich set of built in functions in python, so the answer is off course their is a functions in python to join a list of strings to a single string .as the name suggest join() is the function in python to join a list of strings to a single string.Let we check the syntax of join().
string.join(list)
where string is the separator string and list is a list of strings
item= [‘ Hello’, ‘good morning ‘]
string = ‘,’.join(item)
print(string)
Modules and Packages are the most important and widely used concept in python.Modules and Packages support reusability and easy coding for programmers.
A Modules is simply a single python file with extension .py. Modules contains global variables and group of functions .Modules is a single executable .py files.we can use functions and global variables in module in any python page by simply importing that module in that page.Here is the example usage of a Modules
Module calculator.py
def sum(a,b): sum = a + b print("The sum is: ", sum)
Importing and calling that Module import calculator calculator.sum(3,4)
Packages is a collections of modules, it simple a directory that contains lots of modules and a __init__.py file.The package may contains sub package .
employee(Package)
| __init__.py (Constructor)
| contact.py (Module)
| department.py (Module)
| salary.py (Module)