Thursday, June 25, 2015

Python Datatypes

As I have told you in the previous post that Python is intelligent enough to know the type of variable by assignment. i.e.
A=5 , is an assignment where Python interpreter automatically sets the type of variable A as integer.
If we take another variable b=2, it will also be integer type.
Not of we try to divide A by b , what will be the result do you think?
>>c=A/b?
>> 2
Why? As integer divided by integer is always integer. Of we convert any of the variables to float we will get float as result. i.e.
>>b=2.0#Automatically set b as float by seeing the float point declaration.
Now,
>>c=A/b
2.5
Other than integer we have string variables, we assign them with a single or double quotes.
>>my_name="I am Anthony"
Or
>>my_name='I am Anthony'
But we can not write like this-
>>my_name="I am Anthony' or 'I am Anthony"
Remember to use same quote at start and at the end.
To write something like  "what's your name ” we have to write exactly like this
>>" what's your name"
Using double quotes for declaring string and single quote for the inner one.
String is huge subject , we will discuss more about it as we go on.
The next entry will be about lists, they day those are 'arrays on steroid'

No comments:

Post a Comment

Feautured Post

Python Trivia Post: enumerate()

Python has a very useful inbuilt function, which is called enumerate(). This is needed whenever you need the numbering of a certain element...