29

Defination:

A variable is the name given to a memory location. A value-holding Python variable is also known as an identifier.

Creating Variables:

Example: 

x = “vivek”
print(x)

Example: 

y  = 5
print(y)

Variable Naming Rules:

  • Variable names can contain letters (a-z, A-Z), digits (0-9), and underscore (_).
  • Variable names cannot start with a digit.
  • Python keywords cannot be used as variable names.

Variable names are case-sensitive (age, Age, and AGE are different variables).).

  • PYTHON DATA TYPES

In programming, data type is an important concept.

  • Numeric Types
  • Sequence Types
  •  Mapping Type
  •  Set Types
  •  Boolean Type
  1.  Numeric Types
  • int: Integer type, which represents whole numbers.    

                       Example:            X=5

  • float: Floating-point type, which represents decimal numbers.        

                       Example:             X=20.5

2.  Sequence Types

  • str:  String type, which represents sequences of characters (text).
  • list:  List type, which represents ordered collections of items.
  • tuple:   Tuple type, which represents ordered immutable collections of items.

Example.

string_var = "Hello, Python!"
print(type(string_var))

Example.

  my_list = [1, 2, 3, 4, 5]
print(my_list)       
print(my_list[0]) 

3.Mapping Type

dict: Dictionary type, which represents key-value pairs where keys must

 be unique.

Example:

dict_var = {'a': 1, 'b': 2} 
print(type(dict_var))

4.Set Types

set: Set type, which represents unordered collections of unique items.

frozenset: Immutable set type, similar to set but immutable once created.

Example.

set_var = {1, 2, 3}
print(type(set_var))

Example.

frozenset_var = frozenset({1, 2, 3})
print(type(frozenset_var))

5. Boolean Type

bool: Boolean type, which represents truth values (True or False).

Example.

bool_var = True
print(type(bool_var))

Write A Comment