Python Casting | Specify a Variable kind

Python Casting | Specify a Variable kind

Specify a Variable kind

There is also times after you need to specify a kind on to a variable. this may be finished casting. Python is associate object-orientated language, and per se it uses categories to outline knowledge sortsas well as its primitive sorts.

Casting in python is thus done victimisation builder functions:
int() – constructs associate range|number} number from associate whole number literal, a float literal (by rounding error right down to the previous whole number), or a string literal (providing the string represents an entirenumber)float() – constructs a float range from associate whole number literal, a float literal or a string literal (providing the string represents a float or associate integer)str() – constructs a string from a good sort of knowledge sortsas well as strings, whole number literals and float literalsExampleIntegers:
x = int(1) # x are going to be 1y = int(2.8) # y are going to be 2z = int(“3”) # z are going to be three
x = float(1) # x are going to be one.0y = float(2.8) # y are going to be two.8z = float(“3”) # z are going to bethree.0w = float(“4.2”) # w are going to be four.2
x = str(“s1”) # x are going to be ‘s1’y = str(2) # y are going to be ‘2’z = str(3.0) # z are going to be ‘3.0’

Python Casting | Specify a Variable kind

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *

Domain & free Hosting


You have successfully subscribed to myprogrammingschool

There was an error while trying to send your request. Please try again.

My Programming School will use the information you provide on this form to be in touch with you and to provide updates and marketing.