Data Types and Variables in Python.

Variables in python can be used without the data types. The type of variable is decided at the run time depending upon the data stored. Variable in python can not be used without assigning the values. In python, a number of bytes allocated for a variable is not fixed. It depends upon the amount of data stored in the variable. In another programming language, the number of bytes for a variable is fixed. As a result of this, we can store the data within the specified range only.

Variable in pythonVariable in c, C++, Java
a = 10int a; a =10;
a = [10,20,30]int a[3];
Examples of variables

Rules to name a variable.

  1. A variable name can either start with an underscore or a character.
  2. The character in the variable can either be a-z, A-Z or 0-9.
  3. White-space/wide-space are not allowed in variables.
  4. Variables names cannot begin with a digit.
  5. Variables are case sensitive.
  6. Keyword cannot be used as a variable names.
Valid Variable NamesInvalid Variable Names
_ramu9Ramu, 9ramu
ramuRama Singh(in middle there is a space)
Ram8uclass, for, in, is (keyword in python)
RAMA, rama (two different variables due to case sensitive property)8Ramu9
Example of Valid and invalid variable names

Various data types in python

Data TypesCategoryExamples
intIntegersa = 10, b = 50, c = 5000000000
floatFloating pointa = 10. 002, b = 40.0 c = 80.000001
complexComplex numbera = 2 + 1J (need to give coefficient of imaginary part else error)
boolBooleanTrue, False
strStrings“Ramu”, “Rama”,devqwuu897@$%”
listList or array[10,’10’,’rama’] (heterogeneous array/list), [10,20,90] (homogeneous list/array)
dictDictionary{“name”:”Rama”,”age”:18, “course”:”BE”}
tupleTuple(10,), (10,20,30)

Contributed by – Devanshu Kumar

Contribute your article –

Leave a Comment

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock