Python Devlopment






Variables



2.1 Variables:

In other programming languages, when we declare variables, the it requires type of that variables like int, float, char etc but in there is no command to declare variable. A variable is created the moment you first assign a value to it.

Example:

a=10
b=”Harish”
c=10.4
print(a)  
print(b)
print(c)

Output:
10
Harish
10.4

A variable can have a short name (like a,b,c) or more descriptive name (name, surname, total_area).

 

2.1.1 Rules for Python variables:

  • A variable name must start with a letter or the underscore character

  • A variable name cannot start with a number

  • A variable name can only contain alphanumeric characters and underscores (A-z, 0-9, and _ )

  • Variable names are case-sensitive (name,Name and NAME are three different variables)

 

2.1.1 Numeric Types:

There are three numeric types in Python:

  • int

  • float

  • Complex

a=10          #int
b=10.4      #float
c=10j        #Complex

We can test type of any object in python by using type() function.

Example:

a = 10
b = 10.4
c = 10j
print(type(a))
print(type(b))
print(type(c))

Like other programming languages, in python, there is no limit for integer variable and also consider positive and negative value

Example

a=10
b=123149874521547
c=-20

Other programming languages have some upper limit.