Python Variables and its Usage

Python is considered to be a most useful easiest out of programming languages available and has a lot of importance in software industry let us see usage of python variables.

In this part of the tutorial we will be seeing the usage of the python variables in programming, generally in python variables can be thought of as containers

In Python, a variable is a name that refers to a value stored in memory. Variables are used to store and manipulate data in a program.

In python we need not specify the type explicitly python will consider the value specified and considers the variable of that particular type in any another programming language we might have to specify the type of the variable..

Python has a dynamic typing system, which means that the data type of a variable is determined at runtime based on the value that it is assigned.

Variables in Python can also be used to reference complex data structures like lists, dictionaries, and objects.

Python has several built-in data types that can be used for variables:

Numbers:

Python supports integer, float, and complex numbers. Integers are whole numbers, floats are numbers with decimal points, and complex numbers have both real and imaginary components.

Strings:

Strings are sequences of characters that are enclosed in quotes (either single quotes or double quotes).

Booleans:

Booleans represent the truth values True and False.

Lists:

Lists are ordered sequences of values that can be of any data type.

Tuples:

Tuples are similar to lists but are immutable, which means that their contents cannot be changed after they are created.

Sets:

Sets are unordered collections of unique values.

Dictionaries are unordered collections of key-value pairs.

Dictionaries:

In addition to these built-in data types, Python also supports user-defined data types through the use of classes and objects.

For example let us consider

x = 10
y = 20

Here variable x and y is considered as a variable of type int. As we have declared 10, 20 in python variables can be thought of as it recognise the data type to be integer.

Now when you specify

x + y

30

is printed in next line

Python Variables Video Tutorial :

Based on the index values you can fetch the alphabet / character specified in the word.Its also called as indexing concept very much useful though.

x = 'python'
x[0]

‘p’

So why we are seeing this example is to let you know how we can make use of variable declaration and usage in python

In python code is easily readable no complicated syntax is provided which makes it much easier for everyone to use and it’s the main reason even to get such a popularity.

And also slicing concept where we can find the characters from given range. i..e, you need to provide start and end for a range and in between text is considered as a slice.

x = 'python'
x[0:2]

‘py’

So summary is we have covered indexing, slicing, length of the word.

The video tutorial we provided here explains python variables examples concepts with a clear explanation regarding the variables and its usage.

python variables

Complete python playlist :

Go through the below beginners course

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x