Python Type of Variable

Python Type of Variable
Python Type of Variable


Python Type of Variables

Variable is a name that is used to refer to memory location. Variable also is known as an identifier and used to hold value.

Python, we do not need to specify the type of variable because python is a type integer language and smart enough to get variable type.

Variable names can be a group of both letters and digits, but they have to begin with a letter or an underscore and are recommended using lowercase letters.

Identifier Naming

Variable is the example of identifiers. an Identifier is used to identify the literals used in the program. The rules to name an identifier are given below.

  • The first character of the variable must be an alphabet or underscore(_).
  • All the characters except the first character may be an alphabet of lower-case(a-z),under-case(A-Z),underscore or digit(0-9).
  • Identifier name must not contain any white-space or special character(! ,@,#, %,^,&,*).
  • Identifier name must not be similar to any keyword defined in the language.
  • Identifier name case sensitive for example my name, and MyName is not the same.
  • Examples of valid identifiers: a123, _n, n_9, etc.
  • Example of invalid identifiers: 1a, n%4, n 9, etc.

Declaring Variables and Assigning Values

Python does not bound to declare a variable before using it in the application. It allows us to create variables at the required time.

We do not need to declare explicitly variables in python. When we assign any value to the variable that the variable is declared automatically.

The equal(=) operator is used to assign a value to a variable.

Example

id=807714

name="icoderweb"

rollno=402370


More Related Languages

C Programming Language

C++ Programming Language

Java Programming Language

PHP Programming Language

Projects Programming Language


Multiple Assignment

Python allows us to assign a value to multiple variables in a single statement which is also known as multiple assignments. 

We can apply multiple assignments in two ways either by assigning a single value to multiple variables or assigning multiple values to multiple variables. 

Assigning single value to multiple variables

1. Example

a=b=c=100
print(a)
print(b)
print(c)

*****OUTPUT******
100
100
100

2. Example

a,b,c=100,200,300
print(a)
print(b)
print(c)

*****OUTPUT******
100
200
300


Basic Fundamentals:

This section contains the basic fundamentals of python-like.

1. Token and their types.

2. Comments

(A) Tokens:

  • The token can be defined as a punctuator mark, reserved words, and each individual word in a statement.
  • The token is the smallest unit inside the given program.

There are the following tokens in python.

1. Keyword
2. Identifiers
3. literals
4. Operators

Tuples:
  • A tuple is another form of collection where different types of data can be stored.
  • It is similar to a list where data is separated by commas. Only the difference is that list uses a square bracket and the tuple uses parenthesis.
  • Tuples are enclosed in parenthesis and can not be changed.

Example

str_tup=("Python","Java","Programming")

int_tup=(80,77,14,78,96)

print("String  Tuple:",str_tup[2])

print("Integer Tuple:",int_tup[1])

*****OUTPUT*****

String  Tuple: Programming

Integer Tuple: 77


Dictionary:
  • Dictionary is a collection that works on a key-value pair.
  • It works like an associated array where no two keys can be the same.
  • Dictionaries are enclosed by curly braces({}) and values can be retrieved by a square bracket([]).

Example

student={

 "name":"icoderweb", 

 "rollno":807714, 

 "email":"icoderweb@gmail.com", 

 "address":"Delhi" 

print("Student Name:",student["name"]) 

print("Student Roll No:",student["rollno"]) 

print("Student Email:",student["email"]) 

print("Student address:",student["address"])

*****OUTPUT*****

Student Name: icoderweb 

Student Roll No: 807714 

Student Email: icoderweb@gmail.com 

Student address: Delhi 


Post a Comment

0 Comments