Python Variable & Data Type

Python-Variable-Data-Type

In the previous tutorial, you’ve got learned regarding a way to write and run your initial Python program to print greeting World. This tutorial can assist you to know regarding Python variables and knowledge sorts.

Python Variables

Variables are the name of memory locations to store values. Variables are simple to use and work at intervals Python setting. you only got to kind the name of any variable with none datatype declaration and therefore the Python setting can mechanically get to understand what datatype worth the variables have.

Example

a=5
print(a)

Output

5

The declaration of a datatype is non-mandatory in Python. Here, we’ve directly appointed the worth ‘5’ to the variable ‘a’ that takes it as an associate number. In Python, we will use multiple assignments at one single purpose of your time.

a=b=c=5
print(a,b,c)

Output

(5, 5, 5)

Here are another workarounds with print command in Python.

To include the apostrophe in a very print command, we will screw with the subsequent technique.

print("Hello World by 'justtechreview.com'")

Output

Hello World by ‘justtechreview.com

You can use an apostrophe(‘) at intervals a print statement however it has to be within double quotation marks just in case you would like to use apostrophe within the String.

print(‘Hello World ‘justtechreview.com‘ ”) isn’t a legitimate statement and can generate an error.

To use the print command with Strings (statements) on multiple lines.

print\
("""
Hello World
justtechreview.com
""")

Output

Hello World
justtechreview.com

This print command uses a line continuation character i.e., a backslash (\) that permits me to put in writing strings on consecutive lines.

To repeat a String.

a="Just Tech "
print(a*10

Output

Just Tech Just Tech Just Tech Just Tech Just Tech Just Tech Just Tech Just Tech Just Tech Just Tech

Here, the multiplication operator or the asterisk acts as a repetition operator that multiplies and displays the string.

Python Data Type

Python has some normal knowledge sorts outlined in its library content. These are mentioned below.

Dictionary

Python provides me to create dictionaries with the employment of Hash Table ideas. These are kind of like associative sorts or hashes and makes use of keys and values associated with them. Dictionaries are declared with braces and values or knowledge are often accessed exploitation brackets [].

dictionary1= {'Name':'Durgesh Kaushik','Age':'21', 'Class':'BE'}
print "dictionary1['Name']: ", dictionary1['Name']
print "dictionary1['Age']: ", dictionary1['Age']
print "dictionary1['Class']: ", dictionary1['Class']

Output

dictionary1[‘Name’]: Durgesh Kaushik
dictionary1[‘Age’]: 21
dictionary1[‘Class’]: BE

String

Python provides Me to store Strings within the programs kind of like String of characters in C. It will be enforced as below.

name="Just Tech"
print(name)

Output

Just Tech

String Concatenation

You can merge or concatenate 2 completely different strings into one string in Python. This practicality will be achieved by victimization the + operator.

Example

a="Hello "
b="World"
print(a+b)

Output

Hello World

Tuple

A tuple may be a sequence knowledge kind in Python. it’s greatly kind of like lists in Python. Tuples consist of knowledge separated by a comma. However, the distinction between lists and tuples is that tuples use parentheses () whereas lists use brackets []. Also, the information within the Tuples once outlined can not be altered. But, just in case of lists, knowledge will be modified or altered presently once declaration and definition. Implementation of Tuples in Python is as follows:

tuples=('the',4.3,'Just',3432,'Tech')
print(tuples)

Output

(‘the’, 4.3, ‘Just’, 3432, ‘tech’)

Number

Number knowledge kind is employed to store numeric data values in Python. It includes the subsequent domain of values.

int: It represents the whole number values. It typically stores signed whole number values.

float: It represents floating purpose values, typically real values with decimals.

complex: It will store complicated numbers in python variables.

long: It can store long integers which might successively store positional representation system and positional representation system values.

List

List in Python provides Me with a structure to store multiple things of various knowledge varieties. an inventory is outlined at intervals sq. brackets with single quotation marks or apostrophes. It will be employed in programming as follows:

lists=['the',4.3,'Just',3432,'Review']
print(lists)

Output

[‘the’, 4.3, ‘Just’, 3432, ‘Review’]

DURGESH

I Love python, so I like machine learning a Lot and on the other hand, I like building apps and fun games I post blogs on my website for Tech enthusiast to learn and Share Information With The World.

Leave a Reply

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

12 − six =

Recent Content