InterviewSolution
| 1. |
Standard Python Functions |
Answer»
The print() function prints some specified message to the screen or some standard output device. We can print strings, numbers, or any other object using this function. We can print multiple tokens, and also specify to print the data separated by different delimiters using the print() function. >>> print("Hello World")Hello World >>> var = "Interviewbit" >>> print("My name is ", var) ('My name is ', 'Interviewbit') >>> print("My name is " + var) My name is Interviewbit >>> print(123) 123 >>> a = [1, 2, 3, 4] >>> print(a) [1, 2, 3, 4]
The input() function in Python is used to take any form of inputs from the user/standard input device, which can later be processed accordingly in the program. It is complementary to the print() function. >>> print('Enter your name.')>>> myName = input() >>> print('Hello, {}'.format(myName)) Enter your name. Interviewbit Hello, Interviewbit
The len() function is used find the length(number of elements) of any python container like string, list, dictionary, tuple, etc. # For Lista = [1, 2, 3] print(len(a)) # For string a = "hello" print(len(a)) # For tuple a = ('1', '2', '3') print(len(a))
The ord() function in Python will return an integer that represents the Unicode Character passed into it. It takes a single character as a parameter. Example: # Print unicode of 'A'print(ord('A')) # Print unicode of '5' print(ord('5')) # Print unicode of '$' print(ord('$')) Output: 65 53 36 |
|