wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

PYTHON PROGRAMMING

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

The elements of a tuple are enclosed by ________ .

a)

array bracket

b)

square brackets

c)

parenthesis

d)

Curley brace

2.

The __________ function is used to create Tuples from a list.

a)

tuple

b)

set()

c)

list()

d)

tuple( )

3.

Which of the following is true for a tuple?

a)

Tup = 1,2,3

b)

Tup = (""1,"2)

c)

Tup = (1,2,3,4)

d)

None of the above

4.

In a nested tuple, each tuple is considered as an ------------ .

a)

element

b)

variable

c)

parameter

d)

none of these

5.

The ____________ will be useful to access all the elements in a nested tuple.

a)

if condition

b)

if...elif..else

c)

switch case

d)

for loop

6.

Mandatory arguments required to connect any database from pyton

a)

username, password, hostname, port , database name

b)

user name, password

c)

user name, password, host name

d)

user name, password, host name, database name

7.

Which method of cursor class is used to fetch records from the table

a)

cur.fetchall()

b)

cur.fetchone()

c)

cur.fetchmnay()

d)

cur.fetch()

8.

What is the full form of SQL

a)

Structured Quick Language

b)

Structured Query Language

c)

Structured Query Linking

d)

Structured Query List

9.

SQL command for list databases.

a)

show all;

b)

show all databases;

c)

show databases;

d)

show database;

10.

select the correct statement in python to check SQL connectivity status.

a)

if con_is.connected():

b)

if con.is_connected():

c)

if con_isconnected()

d)

if con.is_connected

11.

select the correct statement to install sql connector library

a)

pip install mysql

b)

pip install mysql.connect

c)

pip install mysql-connector

d)

pip install mysql-connect-python

12.

Which library is used to connect python with MySQL? Write an import statement

a)

import mysql _connector.connect

b)

import mysql.connector() as msq

c)

import mysql.connector

d)

import mysql.connector()

13.

Which function is used to create a cursor object?

a)

cur=concursor()

b)

cur=con.cursor()

c)

cur=con.cursor

d)

cur=con.mycurosr

14.

select the correct sql statement for print records from a database table emp

a)

select all from emp

b)

select * from emp

c)

select * from emp;

d)

select * from emp( );

15.

Examples for list data type

a)

[1,2,3,4,5]

b)

['S','H','R','U','T','H','I']

c)

{1:"a",2:"b",3:"c",7:"d"}

d)

('A','B','C','D')

16.

colors = ["red", "green", "burnt sienna", "blue"]

print(colors[2])


What is the output of the above python code?

a)

'blue'

b)

It causes a run-time error.

c)

'burnt sienna'

d)

'green'

17.

colors = ("red", "green", "burnt sienna", "blue")


print("yellow" in colors)


What is the result of the yellow in colors expression?

a)

ValueError: 'yellow' is not in list

b)

4

c)

False

d)

True

18.

What’s the main difference between Python lists and tuples?

a)

Lists can hold any data type and tuples can only contain int and str objects.

b)

Lists are immutable and tuples are mutable.

c)

Lists are mutable and tuples are immutable.

d)

Lists are faster and tuples are slower.

Check Your Answer »

19.
  1. Identify the DDL commands

a)

create,insert,drop,

update

b)

Insert,update,delete,

select

c)

create,alter,drop,

trucate,rename

d)

grant,revoke

20.

In Python, what happens if you don't commit changes after executing SQL queries?

a)

The changes are automatically committed.

b)

The changes are lost and not saved to the database.

c)

The database connection is closed.

d)

The cursor becomes unresponsive.