Python Basics - Literals
CBSE Class 11 - Informatics Practices
Questions and Answers
Answer: A set of valid characters recognized by python constitutes character set.
Python (from version 3.x onwards) supports the Unicode text. It has the following character set:
Letters: A-Z,a-z
Digits: 0-9
Special symbols: Special symbol available over a keyboard
White spaces: blank space,tab, carriage return, newline, form feed
Other characters: Unicode
Question: Can I type in Hindi in Python 3?
Answer: Yes, Python supports Unicode text, hence one can use multiple languages including Hindi.
Question: What is a token?
Answer: Smallest individual unit in a program is known as a token. It can be:
1. Keywords
2. Identifiers
3. Literals
4. Operators
5. Punctuators
Question: What are keywords in Python?
Answer: Reserve word of the compiler/interpreter which can’t be used as an identifier.
e.g. and, exec, class, True, import, while...
Question: What is an identifier?
Answer: A Python identifier is a name used to identify a variable, function, class, module or other objects.
Question: Are 'Rollnumber' and 'rollnumber' same identifier?
Answer: No, these are different identifiers. Python is cases sensitive.
Question: What are literals in Python?
Answer: Literals in Python can be defined as number, text, or other data that represent values to be stored in variables. They are also called constant values.
Question: What are the different types of literals in Python?
Answer: Different types of literals in Python are:
1. String Literals
2. Numeric Literals
3. Boolean Literals
4. Special Literal None
5. Literal Collections
Question: Give examples of string literals?
Answer: A string literal is a sequence of characters surrounded by quotes (single, double or triple quotes)
fname = "Ramesh"
lastname = 'Sinha'
In the above example "Ramesh" is the string literal, 'fname' is the variable and '=' is the assignment operator.
In Python, one can form string literals by enclosing the text in single quotes or double-quotes.
Question: Is Python a case sensitive language?
Answer: Yes, Python is case sensitive as it treats upper and lower-case characters differently.
Question: What do you mean by escape sequence?
Answer: An escape sequence represents a single character and hence consumes one byte in ASCII representation.
Question: What is the output of print("Pythoo\bn" )
Answer: Python
Escape character '\b' will act as a backspace key and erases extra 'o'.
Question: What is the output of print("Hello\nWorld" )
Answer:
Hello
World
The escape character '\n' will move the cursor to a new line.
Question: How many types of Strings in Python?
Answer: Python allows two string types-
(i) Single-line Strings
(ii) Multiline Strings
Question: How you define the multiple-line string in Python?
Answer. A multiple string defines in triple-quote or triple-apostrophe.
Question: What is Function?
Answer: A function is a named code that can be reused with a program.
Question: Name the function used to find the size of the string. Write its syntax.
Answer: len( ) function is use to find the size/length of an object.
Syntax is: len(<objecy name>)
Question: What is the output of the following python script
stud_name = "Johnny"
print(len(stud_name))
Answer: 6
Question: What do you mean by a comment in Python?
Answer: Comment is non-executable, additional information added in a program for readability.
No comments:
Post a Comment
We love to hear your thoughts about this post!
Note: only a member of this blog may post a comment.