Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
all right everybody so we are moving on to typecasting
typecasting is the process of converting a variable
from one data type to another
we have various functions to convert a value
or variable to a string
an integer a float or a boolean
let's create some variables
we will create a name variable
type in your full name
an age make up some age
a GPA for grade point average let's say minus 3.2
and a boolean of is student
are we currently a student
let's say that's true
now you actually could get the data type of a variable
or a value by using the type function
then pass in a value or variable
however when I run this there's no output
so I need a print statement
we will print what is returned by B type function
get the type of our name variable then print it
so our name variable is a string str
our age variable
is an integer and INT
GPA is a float
is student is a boolean
using these typecast functions
we can convert from one data type to another
here's how
let's start with something simple
let's convert our GPA to an integer
currently it's afloat
I will reassign GPA
use the INT function to typecast to an integer
then pass in my GPA
at the end we will print R GPA
if we typecast 3.2 to a whole integer
what would the result be
a whole integer of 3
we truncate the decimal portion
let's convert our age to a floating point number
we will reassign our variable of age
use the typecast function of float
then insert our age variable
let's print our age variable
and it should be a floating point number 25 point 0
now we'll cover strings
let's typecast our age to be a string
age equals call the typecast function of string
str passenger age variable
so the result is still going to appear the same
25 however it's a string not an integer
and to prove that
I will enclose my age variable with the type function
the type of variable age is a string
it would be the same as if we are taking this number
and enclosing it within quotes
so this would make a difference
because let's say that I add one to age
age plus equals 1
well we would get a type air
can only concatenate strings not integers to a string
however if I were to add a string of 1 to the end
we would be using string concatenation
so let's say it's my birthday and I add 1 to 25
while since we're working with strings now
the result would be 251
I am 251 years old
so strings and numbers behave differently
with numbers
we can use them within arithmetic expressions
strings not so much
we will take our name variable
and typecast it to a boolean
name equals call the typecast function of Bull
Pass in our name variable
this has an interesting result
so I'm going to print name
bullions are either true or false
if I typecast my string of text into a bullion
that gives me true
now it really doesn't matter what I write here
if I were to change my name to a single character
such as B this would still be true
if our string variable
was empty there were no characters within it
that would actually give us false
we could use this to check to see if somebody
enters in their name
or not if somebody types in their name
then we typecast it to a boolean
if somebody skips entering in their name
that would return false
we could reprompt the user to enter in their name again
art everybody so that is typecasting
it is the process of converting a variable
from one data type to another
this is especially useful with handling user input
because user input is always a string
there may be
at times where you want to convert it to an integer
a float or a boolean
and well everybody that is typecasting in Python
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.