Introduction to Programming - Variables 2
Hello you all! today we are going write our first codes! lets start.
our first code is "print()" with that little guy you can write sth on your terminal
As you can see it gave me error when i tried to write its because of it tried to write a variable if i want
it to write it I should write it in nails like this
now i can write anything I want! and I want to define a variable i need to write it as "first variables name then value like this myAge = 16 it will automaticly make myAge variable a integer but if you wanna be sure about its a integer you should write myAge = int(16) and if you write print(myAge) it will write "16" there is other function named type and if you write sth like this print(type(myAge)) it will show you myAge variables type. So our terminal says <class 'int'> lets make myAge float and write its type and value
myAge = float(16)
print("my age is " + myAge + " myAge variables type is " + type(myAge))
it gives us error
print("my age is " + myAge + " myAge variables type is " + type(myAge))
TypeError: can only concatenate str (not "float") to str
so we need to convert "myAge" and "type" to a string like this
print("my age's "+str(myAge)+" myAge variables type is "+str(type(myAge)))
and our terminal says my age is 16.0 myAge variables type is <class 'float'>
thats all for now see you on next blog!


Yorumlar
Yorum Gönder