Learn Python - Python tutorial - python data types - Python examples - Python programs
Strings in Python
A string is a sequence of characters. It can be declared in python by using double quotes. Strings are immutable, i.e., they cannot be changed.
python - Sample - python code :
Lists in Python
Lists are one of the most powerful tools in python. They are just like the arrays declared in other languages. But the most powerful thing is that list need not be always homogenous. A single list can contain strings, integers, as well as objects. Lists can also be used for implementing stacks and queues. Lists are mutable, i.e., they can be altered once declared.
python - Sample - python code :
python programming - Output :
Tuples in Python
A tuple is a sequence of immutable Python objects. Tuples are just like lists with the exception that tuples cannot be changed once declared. Tuples are usually faster than lists.
python - Sample - python code :
python programming - Output :
Iterations in Python
Iterations or looping can be performed in python by ‘for’ and ‘while’ loops. Apart from iterating upon a particular condition, we can also iterate on strings, lists, and tuples.
Example1: Iteration by while loop for a condition
python - Sample - python code :
python programming - Output :
Example 2: Iteration by for loop on string
python - Sample - python code :
python programming - Output :
Example 3: Iteration by for loop on list
python - Sample - python code :
python programming - Output :
Example 4 : Iteration by for loop for range
python - Sample - python code :
python programming - Output :