Files
LearnPython/LearnTheBasics/2_VariablesAndTypes.py
2024-09-13 15:12:25 +02:00

30 lines
1.2 KiB
Python

myint = 7
print(f"The myint variable which contains: {myint}, type is: ", type(myint), "\n")
myfloat = 7.25
myfloat = float(7)
print(f"The myint variable which contains: {myfloat}, type is: ", type(myfloat), "\n")
mystring = "HOLA!" #The difference between the two is that using double quotes makes it easy to include apostrophes
mystring = 'HEY!!'
print(f"The myint variable which contains: {mystring}, type is: ", type(mystring), "\n")
#Assignments can be done on more than one variable "simultaneously" on the same line like this
a, b = 3, 4
print(a, "\n" + str(b))
#Exercise
#The target of this exercise is to create a string, an integer, and a floating point number. The string should be named mystring and should contain the word "hello". The floating point number should be named myfloat and should contain the number 10.0, and the integer should be named myint and should contain the number 20.
# change this code
mystring = "hello"
myfloat = float(10)
myint = 20
# testing code
if mystring == "hello":
print("String: %s" % mystring)
if isinstance(myfloat, float) and myfloat == 10.0:
print("Float: %f" % myfloat)
if isinstance(myint, int) and myint == 20:
print("Integer: %d" % myint)