Python print variable

How to Print Python Variable?

In this Lecture, we are going to learn how to Python print variables and its Python Data Types in Python 3.

You can declare a variable without its Data Types in Python. It will automatically judge it’s the data type of any variable with respect to its given value.

Firstly, we discuss what are variables and why we can use it in its program.

Do you want to know, How to Python print variables? Oh really, let’s start…

 Variable: it is used to store or hold any value in the program. 

Python print variable

Simple write the variable’s name without any data types. Also, initialize its value with an equal sign.

name= "ABDUL JABBAR"

Don’t need to declare string Data Type in Python. And, you don’t need to include the semicolon (;) as well. As we write the second variable.

age= 23

You don’t need to declare its integer data type as well.

marks=988.0

You don’t need to declare the Float Data Type as well.

How to make multiple Variables in a single line and also initialize its value

We can make the different variables in a single line that is separated by a comma (,).

Sname, Sage, Smarks = "ABDUL JABBAR", 23, 988.0

#We can access this varibale simply as:

print (Sname)
Output: ABDUL JABBAR

print(Sage)
Output: 23

print (Smarks)
Output: 988.0

You can access separately every single variable where you want to access by its name.

You can also assign a single value for more than one variable.

Like

Ali= Ahsan= Bilal = "White shirt"
print (Ali)
Output: White shirt

print (Ahsan)
Output: White shirt

print (Bilal)
Output: White shirt

Same as it is we can access the single value through multiple variables in the program.

Python data types in Python 3

Python Data Types in Python 3

  1. Numbers
  2. Strings
  3. List
  4. Tuple
  5. Dictionary

We can write about the student’s age variable (Sage=23). I said that there is no need to declare it’s the Data type.

Because in Python variable type can be judged by its value which is given. We are going to prove how to judge Python Data Types in Python 3 automatically.

We can write the name of a variable with a type keyword to find its data types. Like the Sage variable bellow

Sage = 27 # student age
type(Sage)
Output: <class 'int'>

As we can declare a string variable and find its type Like

Sname = "ABDUL JABBAR" # Student name
type(Sname)
Output: <class 'string'>

Smarks = "988.0"
Type(Smarks)
Output: <class 'float'>

Python automatically stores Value according to its Data Types.

I hope you can understand how to Python print Variables and its Python Data types in Python 3.

Categorized in: