Basic Types and How to Use it in Python. Mastery 09.

A type in Python is a category of data which have the same characteristics that distinguishes them as a class or group.

The basic types in Python are integers, float and strings.

Integers are whole numbers from negative to infinitive. An integer could be -100, 32, 34, 1234, etc.

Float numbers are numbers with decimal point, such as 3.1416, -2.39, 3.2, etc. 

String data contains a string of letters enclosed between quotation marks. If numbers are between quotation marks (like ‘17’ or ‘3.4’ ) their type is string.

 

Assigning a type to a variable

To assign the string type to a variable, you need to write something like this I your code:

M = ‘This is the string of letters I want to assign to the M variable’

Being This is the string of letters I want to assign to the M variable the string set of characters you want to assign to the variable.

To assign the integer type to a variable, you need to write the name of your variable, followed by an equal sign and the number after it. Like in here:

                B = 2

To assign the float type to a variable, you need to write the name of your variable, followed by an equal sign and the number with decimal point after it. Like in here:

                C = 3.1416

 

Assigning a type to a variable through an input.

To assign the integer type to a variable in Python through an input, you need to write the following line of code:

A = int(input(“Write the number you want to assign the integer type”))

Being write the number you want to assign the integer type an example of message to print in the shell.

To assign the float type to a variable in Python through an input, you need to write pretty much the same, but using float instead of int.

B = float(input(“Write the number you want to assign the float type”))

Being write the number you want to assign the float type an example of message to print in the shell.

To assign the string type to a variable in Python through an input, you need to write a similar line of code like in the previous examples.

                C= str(input(“Write the string of data you want to assign to this variable”))

This is pretty much how a type works in Python.

CC BY 4.0 Basic Types and How to Use it in Python. Mastery 09. by Ismael Lizárraga is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.