Python – Change data types | Type Conversion

Python – Change data types | Type Conversion

Python defines type conversion functions to directly convert one data type to another which is useful in day to day and competitive programming. This article is aimed at providing the information about certain conversion functions.
  • int(a,base) : This function converts any data type to integer. ‘Base’ specifies the base in which string is if data type is string.
  • float() : This function is used to convert any data type to a floating point number

Note:

[highlight bgcolor=”#000000″ txtcolor=”#eeee22″]

str + int→ Error

str * str→ Error

str + str→ str

str * int→ strstrstr… int multiple

[/highlight][highlight bgcolor=”#000000″ txtcolor=”#eeee22″][/highlight]

Example

print("5" + "5")
print((int("5") + int("5")) * 10)
print(int("5") + int("5") * 10)
print(int("5" + "5") * 10 )
print(("5" + "5") * 10 )

output :

55
100
55
550
55555555555555555555

 

Hits: 39

CATEGORIES
TAGS
Share This

COMMENTS

Wordpress (0)
Disqus ( )
%d bloggers like this: