Dictionaries in Python

What is Dictionary in python?
  • Dictionary is an unordered collection of data in the form of key-value pair.
  • First element in the key-value pair is the key and the second element is the value.
  • Like list, dictionaries are mutable.
Creating a dictionary
  • Dictionaries are written inside curly brackets ({}) with comma-separated key-value pairs.

Tuples in Python

1) What is Tuple?
  • Just like List, Tuple is a collection of ordered element. But the difference between list and Tuple is, tuples are immutable i.e. the elements in the Tuple cannot be changed, once it is assigned.
  • Tuples also can store both homogeneous and heterogeneous elements.
2) Creating a Tuple
  • Tuples can be created by placing all the elements separated by commas inside parentheses().

Sets in python

What is Set?
  • Set is an unordered collection data type with no duplicate elements. (unique elements)
  • Using curly braces {} or keyword set, we can create a set in Python.
  • In general, the set function is used to eliminate duplicate elements in a list.

Python Comments

Python Comments:
  • Comments are the lines that are used to make your code more readable.
  • Comment lines are mainly used for documentation purposes to make the readers understand the source code.
  • These are the lines that are skipped during the execution of the program by the compilers and the interpreters.
  • Sometimes, comments can also serve to prevent the execution of a line when testing code.
  • There are three types of comments in python.
    • Single line comments 
    • Multi-line comments
    • Docstring comments

For loop - Python practice program

For loop - Python practice program:

Copy and try on your own.
1) Display sum 1 to 10 number by using for loop

    code:
    '''Display sum 1 to 10 number by using for loop'''
    n=10
    ans=0
    for i in range(1,n+1):
        ans+=i
    print("Sum of 1 to 10 number using for loop:",ans)