Numbers and strings
Python variables can store data of various allowed types. Some of the simplest data types are strings and integers (official names in Python are "str" and "int").
You can print the data type of a variable by using type() function (see example below):
1234#Example of a string variable var = "42" print(var) print(type(var))
In the example above Python will print "42" and will treat this variable as a string.
In the example below it will also print "42", but will treat the variable as integer. You can only apply arithmetic operations to Numeric types (integer or others), not strings.
1234#Example of an integer variable var = 42 print(var) print(type(var))
Swipe to start coding
Analyze the code snippet on the right and fix it so that the program executes.
Løsning
Takk for tilbakemeldingene dine!
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Awesome!
Completion rate improved to 2.33Awesome!
Completion rate improved to 2.33
Numbers and strings
Python variables can store data of various allowed types. Some of the simplest data types are strings and integers (official names in Python are "str" and "int").
You can print the data type of a variable by using type() function (see example below):
1234#Example of a string variable var = "42" print(var) print(type(var))
In the example above Python will print "42" and will treat this variable as a string.
In the example below it will also print "42", but will treat the variable as integer. You can only apply arithmetic operations to Numeric types (integer or others), not strings.
1234#Example of an integer variable var = 42 print(var) print(type(var))
Swipe to start coding
Analyze the code snippet on the right and fix it so that the program executes.
Løsning
Takk for tilbakemeldingene dine!
single
Awesome!
Completion rate improved to 2.33
Numbers and strings
Sveip for å vise menyen
Python variables can store data of various allowed types. Some of the simplest data types are strings and integers (official names in Python are "str" and "int").
You can print the data type of a variable by using type() function (see example below):
1234#Example of a string variable var = "42" print(var) print(type(var))
In the example above Python will print "42" and will treat this variable as a string.
In the example below it will also print "42", but will treat the variable as integer. You can only apply arithmetic operations to Numeric types (integer or others), not strings.
1234#Example of an integer variable var = 42 print(var) print(type(var))
Swipe to start coding
Analyze the code snippet on the right and fix it so that the program executes.
Løsning
Takk for tilbakemeldingene dine!