0% found this document useful (0 votes)
15 views4 pages

Coding-TEST 1 Questions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

Coding-TEST 1 Questions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

BASICS

1. Define print() function?(syntax)


A. Used to display content on the screen. The syntax of print function is:
Print(‘values,…,sep= ‘ ‘,end=’\n’,file=sys.stdout,flush=False
2. How to produce a blank line in python?
Use print()
3. How do you print a string with a newline character?
\n
4. How to write multiline string in python?
Using triple quotes (‘’’ ‘’’’) or (“”” “””)
5. What is Python Indentation?
Space at beginning of code line
Used to represent block of code
6. What is python comments?
Used to represent purpose of code
7. How do you write comment in python?
Using # before the required statement
8. What is python variable?
Named location used to store data in memory temporarily, aka container cuz it contains
values
9. Write python variable name rules?
a. Combination of letters, digits and special characters (_)
b. Must start with letters or special characters
c. Keywords are not allowed to be used as variable
10. Define assignment statement?
Used to assign value or result of expression to a variable
11. How to assign single value to multiple variables?
By writing the expression in one line
Eg- a=b=3
I
Value of 3 assigned to both a and b
12. How to assign multiple values to multiple variables?
By using comma separated variable names on the left side and followed by comma separated
list of values on right side of assignment operator
Eg- a, b=20,30
I
Value of 20 assigned to a, 30 assigned to b
13. Define constant in python?
Variable used to store data permanently
14. How to swap variables in python?
a. Using a temporary variable (c)
b. By mathematical expression
c. Tuple packing and unpacking

15. What is swapping of variables in python?


Refers to exchanging of values of 2 variables
16. What is python keywords?
Reserved words with specific meanings in python language like variable, function, class
names (‘False’, ‘None’, ’and’, ’elif’)
17. Define python Identifiers?
Refers to name of variable, function, class or module
18. What are the rules for writing identifier?
a. Must start with letters or special characters
b. Keywords are not allowed to be used as identifier
19. What is literals in python?
Raw data stored into variable
20. What is Special literal?
None – used to define null variable
21. What is literal Collections?
Used to store multiple values having different datatype
1. List – [1,2,3.4, True, None]
2. Tuple – (1,2,3.4, True, None)
3. Set – {1,2,3.4, True, None }
4. Dictionary – {key: value}
NUMBER AND STRING QUESTIONS

1. How do you import specific function from a module?


Instead of importing the entire module, we can import only the functions or variables we
need using the from keyword.
2. How do you import a module with a different name? (1 mark)
using the from keyword to specify the destination module of the function and import
keyword followed by the function's name.

3. What is number datatype in python? (5 mark)


Consists of int, float, complex
4. Write a note about random module in python? With example
To generate random numbers – choice(), randrange(), random(), shuffle(), uniform(),
randint(), sample()
5. Difference between mutable and immutable datatype?
Mutable – can be modified (list,set,dict)
Immutable – cannot be modified(numeric,str,tuple)
6. Explain difference between int and float?
Int- does not contain decimal wereas float does
7. What is a complex datatype? `
In the form of a+bj where, a and b are floats
8. What is a Boolean datatype?
It is one of python built in datatype. Boolean datatype can be one of two values,
either True or False. It is used to test whether result of an expression is true or false.
9. What are Boolean values in python?
True and False
10. How do you convert a numeric value into complex?
To convert a numeric value into its complex representation, you essentially add a zero to
imaginary part
11. How do you convert a float into integer?
by using the math.floor() function

12. How do you convert string into float?


Using float() function
13. How do you access elements from a string? (3 mark)
Using indexing and slicing
Indexing – access individual character
Slicing – access range of characters [start:stop:step] stop value +1
14. What is enumerate() function in python? With example
Returns enumerate object
Contains index no and value of all items in string as pair
15. How do you check and find datatype of a variable in python?
Using isinstance() to check and type() function to find
16. Define type() function in python?
Used to find datatype of variable in python
17. What are some common string operators in python?
a. Concatenation (+) – joins two string together
b. Repetition (*) – repeats a string the specified no of times
18. How to join two strings in python?
By concatenation (+)
19. What is string concatenation in python?
Joining of 2 or more strings together
20. How to multiply string into given number of times?
Using * operator
21. How do you check if an element is present in a string or not?
By using keyword ‘in’ to check if substring exists within a string or not

You might also like