Welcome
So today here you are going to learn about variables and different data types in python.
Variables and Datatype in Python |
Variables and Datatypes
Python is completely object-oriented and is not "statically typed", So you need not declare variables or there type before using them.
Remember that every variable in python is an object.
Now, let's learn about some basic data types.
Now, let's learn about some basic data types.
Numbers
Python supports two types of numbers: integers and floating types ( It also supports complex numbers which would not be included in this tutorial)
The Syntax for using an integer is:
(Run the code to see the output)
(Run the code to see the output)
And for using floating-point numbers you may use the below syntax:
Strings
For making strings in python we either use double or single quotes.
For Example:
Note: Remember one thing you could add two numbers or strings, but you could not add a number with a string, however multiplication of a string with a number can be possible
Whenever we add to strings the process is called concatenation, whereas multiplication of string with a number is called replication.
Exercise:
Here is a small exercise for you, here you have to change the value of the variables and put "Hello" as the value of the variable mystr and 7 as the value of the variable myint and 9.99 as the value of the variable myfloat.
And get the output:
And get the output:
Hello
7
9.99
Comments
Post a Comment