Help me to understand this code I am absolute beginner

a=5

print(“Type of a:”,type (a))

b = 5.0

print(“\nType of b:”,type(b))

c = 2+4j

print(“\nType of c:”,type(c))

What exactly is giving you troubles?

You are assigning values to variables and then printing out the type of object that is created.

More info here: https://www.geeksforgeeks.org/python-type-function/

Here the print() function parses '\n" as a ‘go to the new line’ command rather than just the letter ‘n’, then it print whatever in “” and then parses the built-in type() function which checks for types and here is given variables ‘a’, ‘b’, ‘c’ to check their types.

In Python (and many other prog. languages), ‘=’ sign functions not as a standard equals sign in math meaning equality. In Python ‘=’ sign is an assignment operator and means that value 5 was assigned to a variable name ‘a’. So now variable name ‘a’ points to a chunk of memory where value 5 is stored and is associated with this chunk of memory.

Functions are reusable blocks of code performing some specific function and generally have a format with parenthesis name(). They receive their inputs in parenthesis separated by commas. The output of one function can be piped as input to another function. The output of type() function is chained into print() function. And here print() function receives multiple inputs to print: text characters enclosed in quotes “string” and the output of type(a) function call which determines the type of variable with the name ‘a’.

\ - is an escape character and instructs the print() function to not interpret the subsequent character as letter ‘n’, but to interpret it as a new line command.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.