print command
print command is used to print a message on the screen or other standard output device. The message can be a string or any other object. The print command can be used to print any type of object like integer, string, list, tuple, etc.
Syntax: print(object)
type command
type command is used to check the type or class of an object.
Syntax: type(object)
range command
range command is used to generate a sequence of integers starting from 0 by default to n where n is not included in the generated numbers. We use this command in for loops mostly.
Syntax: range(start, stop, step)
- start refers to the starting of range (Optional; 0 by default )
- stop refers to the number before which you want to stop (Mandatory)
- step refers to the increment count (Optional; 1 by default)
Note: If you provide two parameters to range() function, it will always consider them as (start,stop) and not as (stop,step).
round command
round command is used to round a number to a given precision in decimal digits. That means if you have so many digits after decimal in a float point number then you can use the round command to round off the specified number. You can mention how many digits you want after the decimal point.
Syntax: round(number, digits)
- number refers to the floating-point number.
- digits refer to the count of digits you want after the decimal point. (Optional; By default 0)
input command
input command is used to take input from the user. The flow of the program will be stopped until the user has entered any value. Whatever the user enters it will be converted into a string by the input function. If you want to take an integer as input then you have to convert it explicitly.
Syntax: input(message)
message refers to the text you want to display to the user. (Optional)
len command
len command or len() function is used to get the number of items in an object. If the object is a string then len() function returns the number of characters present in it. If the object is a list or tuple it will return the number of elements present in that list or tuple. len() gives an error if you try to pass an integer value to it.
Syntax: len(object)
object of which you want to find the length(Required)
Loop commands
In python, we have two primitive loop commands namely while and for. The while loop command is used to execute a set of statements as long as the given condition is true.
Syntax of while loop: while condition:
statements
update iterator
The for loop command is used to execute a set of statements by iterating over a sequence. This sequence can be a list, tuple, string, dictionary, etc.
Syntax of for loop: for x in sequence:
statements