Python Variable MCQ : Set 4

Python Variable MCQ

1). What is the output of the following code?
x = [1, 2, 3]
y = x.copy()
y[0] = 10
print(x)

a) [1, 2, 3]
b) [10, 2, 3]
c) [1, 2, 3, 10]
d) None of these

Correct answer is a)
Explanation: The copy() method creates a shallow copy of the list. Modifying the copy does not affect the original list.

2). What is the output of the following code?
x = “Hello”
print(len(x))

a) 5
b) 6
c) 10
d) None of these

Correct answer is a)
Explanation: The len() function in Python returns the length of a string. In this case, len(“Hello”) is equal to 5.

3). Which of the following is the correct way to declare a global variable “x” inside a function?
a) global x
b) x = global
c) x.global()
d) None of these

Correct answer is a)
Explanation: The “global” keyword is used to declare a variable as global inside a function.

4). What is the output of the following code?
x = “Python”
print(x[-2])

a) t
b) o
c) n
d) None of these

Correct answer is a)
Explanation: Negative indexing starts from the end of the string. x[-2] returns the second-to-last character, which is “t”.

5). What is the output of the following code?
x = “Hello”
print(x[::-1])

a) Hello
b) olleH
c) ello
d) None of these

Correct answer is b)
Explanation: The slicing [::-1] reverses the string. In this case, “Hello” reversed becomes “olleH”.

6). Which of the following is a valid way to check if a variable “x” is of type float?
a) type(x) == float
b) x.type() == float
c) typeof(x) == float
d) None of these

Correct answer is a)
Explanation: The type() function is used to check the type of a variable. The comparison “type(x) == float” checks if “x” is of type float.

7). What will be the value of the variable “x” after the execution of the following code?
x = [1, 2, 3]
y = x
y.append(4)

a) [1, 2, 3]
b) [1, 2, 3, 4]
c) [4, 3, 2, 1]
d) None of these

Correct answer is b)
Explanation: Both variables “x” and “y” refer to the same list object. Modifying “y” will also modify “x” since they point to the same memory location.

8). What is the output of the following code?
x = “Hello”
print(x[1])

a) H
b) e
c) l
d) None of these

Correct answer is b)
Explanation: Indexing starts from 0. x[1] returns the second character, which is “e”.

9). Which of the following is true about local variables in Python?
a) They can be accessed from any part of the program
b) Their scope is limited to the function or block where they are defined
c) They are declared using the local keyword
d) None of these

Correct answer is b)
Explanation: Local variables are only accessible within the function or block where they are defined.

10). What is the output of the following code?
x = 2
y = 3
print(x < y)

a) True
b) False
c) 2
d) 3

Correct answer is a)
Explanation: The < operator checks if the left operand is less than the right operand. In this case, 2 < 3 is True.

11). What is the output of the following code?
x = 5
y = 2
z = x % y
print(z)

a) 1
b) 2
c) 0
d) None of these

Correct answer is a)
Explanation: The % operator calculates the remainder of the division. In this case, 5 % 2 is equal to 1.

12). Which of the following is a valid variable name in Python?
a) 1_variable
b) variable_1
c) variable-1
d) variable 1

Correct answer is b)
Explanation: Variable names in Python can contain letters, numbers, and underscores, but they cannot start with a number or contain spaces or hyphens.

13). What is the output of the following code?
x = “Python”
print(x[1:4])

a) Pyt
b) yth
c) tho
d) None of these

Correct answer is b)
Explanation: Slicing extracts a portion of a string. In this case, x[1:4] returns the characters from index 1 to index 3, excluding the character at index 4.

14). Which of the following is the correct way to convert a floating-point number to an integer in Python?
a) int()
b) float_to_int()
c) str()
d) None of these

Correct answer is a)
Explanation: The int() function can be used to convert a floating-point number to an integer in Python.

15). What will be the value of the variable “x” after the execution of the following code?
x = 5
y = x
y = y + 2
print(x)

a) 5
b) 7
c) 2
d) None of these

Correct answer is a)
Explanation: Assigning the value of “x” to “y” creates a copy of the value. Modifying “y” does not affect the original value of “x”.

16). What is the output of the following code?
x = “Python”
print(x[1:])

a) Python
b) ython
c) P
d) None of these

Correct answer is b)
Explanation: Slicing with an omitted end index returns the substring from the start index to the end of the string. In this case, x[1:] returns “ython”.

17). Which of the following is the correct way to declare a constant variable in Python?
a) Use the const keyword
b) Prefix the variable name with an underscore (e.g., _PI)
c) Use all uppercase letters for the variable name (e.g., PI)
d) None of these

Correct answer is c)
Explanation: Although Python does not have built-in support for constant variables, using all uppercase letters for the variable name is a common convention to indicate that it should be treated as a constant.

18). What is the output of the following code?
x = [1, 2, 3]
y = x
y = [4, 5, 6]
print(x)

a) [1, 2, 3]
b) [4, 5, 6]
c) [1, 2, 3, 4, 5, 6]
d) None of these

Correct answer is a)
Explanation: Assigning a new list [4, 5, 6] to “y” does not modify the original list object referred to by “x”.

19). Which of the following is a valid way to concatenate two strings in Python?
a) str.add()
b) str.join()
c) str.append()
d) None of these

Correct answer is b)
Explanation: The str.join() method can be used to concatenate two strings in Python.

20). What will be the output of the following code?
x = 2
y = 3
print(x == y)

a) True
b) False
c) 2
d) 3

Correct answer is b)
Explanation: The == operator checks if the left operand is equal to the right operand. In this case, 2 is not equal to 3, so the expression evaluates to False.

21). What is the output of the following code?
x = 2
x = x * 3
x = x + 1
print(x)

a) 5
b) 7
c) 8
d) 9

Correct answer is d)
Explanation: The code multiplies the value of “x” by 3, adds 1 to it, and assigns the result back to “x”. Therefore, the value of “x” becomes 7, then 8.

22). What will be the value of the variable “y” after the execution of the following code?
x = [1, 2, 3]
y = x
x.append(4)
print(y)

a) [1, 2, 3]
b) [1, 2, 3, 4]
c) [4, 3, 2, 1]
d) None of these

Correct answer is b)
Explanation: When “y” is assigned the value of “x”, it refers to the same list object in memory. Therefore, any changes made to the list through either variable will be reflected in both. The code appends the value 4 to the list, so the value of “y” becomes [1, 2, 3, 4].

23). What will be the value of the variable “x” after the execution of the following code?
x = [1, 2, 3]
y = x
y[0] = 4
print(x)

a) [1, 2, 3]
b) [4, 2, 3]
c) [4, 2, 3, 4]
d) None of these

Correct answer is b)
Explanation: Since “x” and “y” refer to the same list object, modifying the list through one variable will affect the other. The code changes the value at index 0 to 4, so the value of “x” becomes [4, 2, 3].

24). What is the output of the following code?
x = “Hello”
y = “World”
z = x + y
print(z)

a) “Hello World”
b) “HelloWorld”
c) “WorldHello”
d) “HWeolrllod”

Correct answer is a)
Explanation: The + operator in Python can be used to concatenate two strings in Python. In this case, the variable “z” contains the concatenation of “Hello” and “World”, resulting in the string “Hello World”.

25). Which of the following statements is true regarding variable names in Python?
a) Variable names can contain spaces.
b) Variable names can start with a number.
c) Variable names are case-insensitive.
d) Variable names can contain special characters like @ or #.

Correct answer is b)
Explanation: Variable names in Python cannot start with a number. They can only start with a letter or an underscore.

Python Variable MCQ : Set 3

Python Variable MCQ

1). What will be the value of the following variable?
a = 10
a += 5
a -= 3

a) 5
b) 7.5
c) 10
d) 12

Correct answer is d)
Explanation: The code performs arithmetic operations on the variable “a”. The final value of “a” will be 12.

2). What is the scope of a local variable in Python?
a) Restricted to the function where it is defined
b) Accessible from any part of the program
c) Restricted to the class where it is defined
d) None of these

Correct answer is a)
Explanation: A local variable is accessible only within the function or block of code where it is defined.

3). Which of the following statements is true about global variables in Python?
a) They are accessible only within a specific function
b) They can be accessed from any part of the program
c) They can only store numeric values
d) None of these

Correct answer is b)
Explanation: Global variables can be accessed from any part of the program, including functions.

4). What will be the output of the given code?
a = 7
b = 3
print(x // y)

a) 2.5
b) 2
c) 3
d) 2.0

Correct answer is b)
Explanation: The double slash (//) is the floor division operator, which performs integer division and returns the quotient. In this case, 5 // 2 is equal to 2.

5). What is the data type of the following variable?
x = 5.0

a) int
b) float
c) double
d) None of these

Correct answer is b)
Explanation: The variable “x” is assigned a floating-point value, so its data type is float.

6). What will be the output of the given code?
x = “2”
y = 3
print(x * y)

a) 23
b) 6
c) 222
d) TypeError

Correct answer is c)
Explanation: When a string is multiplied by an integer, it repeats the string multiple times. In this case, “2” * 3 results in “222”.

7). What will be the output of the given code?
x = 10
y = “20”
print(x + int(y))

a) 30
b) 1020
c) 102010
d) TypeError

Correct answer is a)
Explanation: The code converts the string “20” to an integer using the int() function and performs addition. The result is 30.

8). Which of the following is an invalid variable name in Python?
a) my-var
b) my_var
c) 123var
d) _var123

Correct answer is a)
Explanation: Variable names cannot contain hyphens (-) in Python. Underscores (_) are allowed.

9). What will be the value of the variable “x” after the execution of the following code?
x = 5
x = x + “2”

a) 7
b) 52
c) TypeError
d) None of these

Correct answer is c)
Explanation: You cannot concatenate a string and an integer using the + operator. It raises a TypeError.

10). Which of the following is the correct way to check the type of a variable “x”?
a) typeof(x)
b) type(x)
c) x.type()
d) None of these

Correct answer is b)
Explanation: The type() function is used to check the type of a variable in Python.

11). What is the output of the following code?
x = 3.8
print(int(x))

a) 3
b) 4
c) 3.0
d) 4.0

Correct answer is a)
Explanation: The int() function converts a floating-point number to an integer by truncating the decimal part. In this case, int(3.8) is equal to 3.

12). What will be the output of the following code?
x = “Hello, World!”
print(x[7:12])

a) Hello
b) World
c) , Wor
d) None of these

Correct answer is b)
Explanation: The code uses slicing to extract the characters from index 7 to 11 (exclusive). This results in the string “World”.

13). Which of the following is true about constant variables in Python?
a) Their values cannot be changed after the assignment
b) They can only store integer values
c) They are declared using the const keyword
d) None of these

Correct answer is d)
Explanation: Python does not have a built-in concept of constant variables. Variables can be reassigned with different values.

14). What will be the output of the following code?
x = 2
y = 3
print(x ** y)

a) 6
b) 8
c) 9
d) 6.0

Correct answer is c)
Explanation: The double asterisk (**) is the exponentiation operator in Python. In this case, 2 ** 3 is equal to 8.

15). Which of the following is an immutable data type in Python?
a) list
b) tuple
c) dictionary
d) set

Correct answer is b)
Explanation: Tuples are immutable, meaning their elements cannot be changed once assigned. Lists, dictionaries, and sets are mutable.

16). What is the output of the following code?
x = “SQATOOLS”
print(x[-3:])

a) OLS
b) LS
c) SQA
d) OOLS

Correct answer is a)
Explanation: Negative indexing starts from the end of the string. x[-3:] extracts the last three characters, resulting in “OLS”.

17). What will be the value of the variable “x” in the given code?
x = 2
x = x * x

a) 2
b) 4
c) 8
d) None of these

Correct answer is b)
Explanation: The code squares the value of “x” and assigns the result back to “x”. So the value of “x” is 4.

18). Which of the following is a valid way to concatenate two strings in Python?
a) str1.add(str2)
b) str1 + str2
c) str1.concat(str2)
d) None of these

Correct answer is b)
Explanation: The + operator in Python is used to concatenate two strings in Python.

19). What is the output of the given code?
x = “Python”
print(x[1:4])

a) Pyt
b) yth
c) thon
d) None of these

Correct answer is b)
Explanation: The code uses slicing to extract the characters from index 1 to 3 (exclusive). This results in the string “yth”.

20). What will be the output of the given code?
x = 5
y = 2
print(x % y)

a) 2.5
b) 2
c) 1
d) 2.0

Correct answer is c)
Explanation: The % operator is the modulus operator, which returns the remainder of the division. In this case, 5 % 2 is equal to 1.

21). Which of the following is a valid way to convert an integer to a string in Python?
a) int_to_str()
b) str()
c) convert_str()
d) None of these

Correct answer is b)
Explanation: The str() function is used to convert an object to its string representation.

22). What is the output of the following code?
x = 2.7
print(round(x))

a) 2
b) 3
c) 2.0
d) 3.0

Correct answer is a)
Explanation: The round() function rounds the given number to the nearest integer. In this case, round(2.7) is equal to 2.

23). What will be the value of the variable “x” after the execution of the following code?
x = [1, 2, 3]
y = x
y[0] = 10

a) [1, 2, 3]
b) [10, 2, 3]
c) [10, 2, 3, 1]
d) None of these

Correct answer is b)
Explanation: Both variables “x” and “y” refer to the same list object. Modifying “y” will also modify “x” since they point to the same memory location.

24). Which of the following is a valid way to convert a string to an integer in Python?
a) int_to_str()
b) str()
c) int()
d) None of these

Correct answer is c)
Explanation: The int() function is used to convert a string to an integer in Python.

25). What is the output of the following code?
x = “Hello”
y = “World”
print(x + y)

a) HelloWorld
b) Hello World
c) Hello+World
d) None of these

Correct answer is a)
Explanation: The + operator concatenates two strings. In this case, “Hello” + “World” results in “HelloWorld”.

Python Variable MCQ : Set 2

Python Variable MCQ

1). What will be the output of the following Python code?
type(10.0)
  a) <class ‘float’>
  b) <class ‘int’>
  c) <class ‘list’>
  d) None of these

Correct answer is a).
Explanation: The value 10.0 is float, so the output of the given code will be <class ‘float’>.

2). What will be the output of the following Python code?
type(10/2)
  a) int
  b) <class ‘float’>
  c) 5
  d) None of these

Correct answer is b).
Explanation: Here, we are not finding the arithmetic value of 10/5, instead we need the data type of 10/5 (i.e. 2.0). So the output will be float.

3). What will be the output of the following Python code?
type(()) is <class ‘tuple’>
  a) True
  b) False

Correct answer is a).
Explanation: Tuples are stored inside round brackets () and the parameter inside type() is an empty tuple. So, the given code on execution will give the output as True.

4). What will be the output of the following Python code?
type([])
  a) <class ‘array’>
  b) <class ‘dict’>
  c) <class ‘list’>
  d) Code will generate an error

Correct answer is c).
Explanation: Lists are stored inside square brackets [] and the parameter inside type() is an empty list. So, the given code on execution will give the output as <class ‘list’>.

5). What will be the output of the following Python code?
type({}) is <class ‘set’>

  a) True
  b) False

Correct answer is b).
Explanation: type({}) produces a dictionary and not a set so the correct answer is b).

6). What will be the output of the following Python code?

bool(-5)
  a) True
  b) False

Correct answer is a).
Explanation: Bool is used to get a truth value of an expression.

7). A variable should be assigned a value before it is declared.
  a) True
  b) False

Correct answer is b).
Explanation: Python determines the type of a variable during runtime based on the value that is assigned to it. So, not necessary to assign a value during its declaration.

8). Which of the following function gives a unique number assigned to an object?
  a) ref()
  b) reference()
  c) id()
  d) type()

Correct answer is c).
Explanation: id() function returns a unique id for the object.

9). How do we define a block of code in Python?
  a) Using curly braces
  b) Indentation
  c) Using Brackets
  d) None of these

Correct answer is b).
Explanation: Identation is used to define a block of code in Python. Curly braces {} are used to define a block of code in other languages like C, C++,.

10). Variable names are case-sensitive in Python.
  a) True
  b) False

Correct answer is a).
Explanation: Variable names are case-sensitive in Python. So, variable1 is different than VARIABLE1 in Python.

11). How do we comment in a single line in Python?
  a) /
  b) \
  c) #
  d) ” “

Correct answer is c).
Explanation: Hash (#) is used to comment the entire line.

12). The following way is correct to assign multiple variables to a single value
      a = b = c = 5
  a) True
  b) False

Correct answer is a).
Explanation: This is a compact way to assign the same value to multiple variables. Here, a, b, and c will have a value of 5.

13). The following way is correct to assign multiple variables to multiple values
a, b, c = “Bikes”, “Cars”, “Trucks”
  a) True
  b) False

Correct answer is a).
Explanation: This is a compact way to assign values to multiple variables. Here, a, b, and c will have “Bikes”, “Cars”, and “Trucks” respectively.

14). What will be the output of the following Python code?
type(4j)
  a) alphanum
  b) long
  c) complex
  d) Error

Correct answer is c).
Explanation: j suffix to 4 (e.g., 4j) indicates the imaginary part. Type for such value returns complex.

15). What will be the output of the following Python code?
type(4l)
  a) alphanum
  b) long
  c) complex
  d) Error

Correct answer is d)
Explanation: Output will produce an error for this Python code. It varies on Python versions. This is valid in Python 2.7.5 and returns “long”.

16). Python supports the conversion of integer variables to complex.
  a) True
  b) False

Correct answer is a).
Explanation: Conversion of integer say x to complex is supported in Python using complex (x) function.

17). Python supports the conversion of complex variables to integers.
  a) True
  b) False

Correct answer is b).
Explanation: Conversion of complex numbers to integers is not supported in Python.

18). What will be the output of the following Python code?
var = “Hello”
int(var)
  a) Hello
  b) H,e,l,l,o
  c) Code will generate an error
  d) None of these

Correct answer is c).
Explanation: This is not supported in Python, and the code will generate an error: invalid literal for int() with base 10.

19). What will be the output of the following Python code?
var = “1234”
int(var)
  a) 1234
  b) 1,2,3,4
  c) Code will generate an error
  d) None of these

Correct answer is a).
Explanation: This will work fine in Python, and the code will produce output 1234 (correct option a).

20). What will be the output of the following Python code?
var = str(1234)
print(var)
  a) 1234
  b) 1,2,3,4
  c) ‘1234’
  d) Code will generate an error

Correct answer is a).
Explanation: This will work fine in Python, and the code will produce output 1234 (correct option a).

21). What will be the output of the following Python code?
str(1234)
  a) 1234
  b) 1,2,3,4
  c) ‘1234’
  d) Code will generate an error

The correct answer is c).
Explanation: This will work fine in Python, and the code will produce output ‘1234’ (correct option c).

22). What is a variable in Python Programming language?
a) A container to store data
b) A function to perform calculations
c) A loop control structure
d) None of these

Correct answer is a)
Explanation: A variable in Python is a name that refers to a value or data stored in the computer’s memory.

23). Which of the following is a valid variable name in Python?
a) 123var
b) var123
c) _var
d) None of these

Correct answer is b)
Explanation: Variable names in Python can start with a letter or an underscore (_), but not with a digit.

24). What will be the output of the following code?
x = 5
y = “Hello”
z = x + y
print(z)

a) 5Hello
b) Hello5
c) TypeError
d) None of these

Correct answer is c)
Explanation: You cannot perform arithmetic operations between different data types. Adding an integer and a string raises a TypeError.

25). Which of the following is not a valid variable type in Python?
a) int
b) float
c) string
d) char

Correct answer is d)
Explanation: Python does not have a separate data type for characters. Characters are represented as strings of length 1.

Python variable MCQ : Set 1

Python Variable MCQ

1). Which is the correct way to get the type of the variable, say for variable x that holds any kind of value?

  a) typedef (x)
  b) pytype (x)
  c) type (x)
  d) None of these

Correct answer is c).
Explanation: Type is a built-in function in Python that returns the class type of the object.
For example: If x is a number (integer), then type(x) will return “<class ‘int’>”.

2). Which is true for the variable names in Python?
  a) underscore is not allowed
  b) only names and special characters are allowed
  c) unlimited length
  d) none of these

Correct answer is c).
Explanation: There is no limit of the variable name length in the python.

3). What is __name__ in python?
  a) this is not a built-in variable
  b) this is a built-in variable
  c) None of these

Correct answer is b).
Explanation:  __name__ is a special or built-in variable that gives the name of the current module.

4). What is a ++ in Python?
  a) this is an increment operator like Java or C++
  b) this is not allowed in Python
  c) this is used as a global variable
  d) none of these

Correct answer is b).
Explanation: There is no ++ incremental operator in Python.

5). What are nonlocal variables in Python?
  a) Those are the same as the global variable
  b) Those are declared within nested functions
  c) There is no way to create nonlocal variables in Python
  d) None of these

Correct answer is b).
Explanation: Variables that are declared within a nested function are called nonlocal variables.

6). What are local variables in Python?
  a) Those are declared inside the function
  b) Those are defined within the local scope
  c) Not accessible outside of the function
  d) All of the these

Correct answer is d).
Explanation: Local variables are defined within a local scope, declared inside the function, and can not be accessed outside of the function.

7). Which is an invalid statement?
  a) testvar = 1000
  b) test var = 1000 2000
  c) test,var = 1000, 2000
  d) test_var = 1000

Correct answer is b).
Explanation: Whitespace is not allowed in the variable name.

8). What will be the value of variable b after the below code execution?
       a = “10”
       b = a + str (5)

  a) 15
  b) 5
  c) 105
  d) Syntax error

Correct answer is c).
Explanation: In this code, we are not adding 5 with 10 arithmetically but, we are adding two strings namely “10” and “5”.

9). Which is not a correct way to assign value to the variable?
  a) x=y=z=10
  b) x,y,z=10
  c) x,y,z=7.5,word,5
  d) None of these

Correct answer is b).
Explanation: Assigning a single value to multiple variables is not possible.

10). What will be the output of :
num = 2.789
print(round(num))
  a) 2.0
  b) 2.79
  c) 3.0
  d) 3

Correct answer is c)
Explanation: The round() function in Python rounds a number to the nearest whole number. In this case, num is 2.789, which is closer to 3 than to 2. Therefore, when you use round(num), it will round up to 3.0.

11). Python Variable must be declared before it is assigned a value:

  a) True
  b) False

Correct answer is b).
Explanation: No need to declare a variable before it is assigned a value

12). What are the things inside the list called?
  a) variables
  b) identifiers
  c) elements
  d) items

Correct answer is c).
Explanation: The things inside the list are called elements.

13). Identify the correct key value pair:
dict = {“Name”:”Rahul”, “Age”:24, “Occupation”:”Lawyer”}
  a) Key is Rahul, Value is Name
  b) Key is Name, Value is 24
  c) Key is Name, Value is Rahul
  d) Key is Name, Value is Age

Correct answer is c).
Explanation: Here, we are asked to identify the correct key value PAIR, so it will be option c).

14). Choose the correct option of the below code:

        def num():
             global a
             a = 20
             a = a+10
             print(a)

        a=10
        num()
        print(a)

  a) 30
       10

  b) 30
       30

  c) 20
       10

  d) 20
       20

Correct answer is b).
Explanation: Inside function num(), variable “a” is initially declared as global and assigned value as 20. Value of “a” will be printed when num() is called.
Variable inside the function will be given preference and hence the output of a will be a = a+10 = 20+10 = 30.
As we have declared “a” as global so when the function ends, outside print(a) will also output 30. So the correct answer is b).

15). What will be the output of the following code:
print(20//7)
  a) 2
  b) 2.0
  c) 2.857142857142857
  d) 3

Correct answer is a).
Explanation: The ‘//’ operator is called the floor division operator. This operator carries out the division and rounds off the value into the nearest whole number.

16). Which of the following is a core data type?
  a) boolean
  b) class
  c) def
  d) none of these

Correct answer is a).
Explanation: Boolean is a core data type.

17). Which of the following is an immutable data type?
  a) Sets
  b) Lists
  c) Strings
  d) Dictionary

Correct answer is c).
Explanation: Strings are an immutable data type as their values cannot be updated.

18). Which of the following is not a data type?
  a) String
  b) Character
  c) Integer
  d) None of these

Correct answer is b).
Explanation: Character is not a data type.

19). Which of the following function does not return any value?
  a) type
  b) int
  c) bool
  d) None

Correct answer is d).
Explanation: type, int, and bool return some value whereas the None function does not.

20). What will be the output of the following Python code?
type(“abcd”)
  a) string
  b) char
  c) str
  d) int

Correct answer is c).
Explanation: “abcd” is stored in a string format so it will return str.

21). What will be the output of the following code?
list1 = [1,2,3,4]
tup1 = tuple(list1)
print(tup1)
  a) [1,2,3,4]
  b) (1,2,3,4)
  c) 1 2 3 4
  d) The code will give an error while running

Correct answer is b).
Explanation: In this code, we are converting a list into a tuple and then printing it, so the output that we will get will be in tuple format.

22). In which of the following data type is stored in “Key – Value” pair format?
  a) Lists
  b) Dictionary
  c) Tuples
  d) None of these

Correct answer is b).
Explanation: In dictionaries, data is stored in key-value pair format.

23). Which of the following cannot be a variable?
  a) pass
  b) fail
  c) Both a and b
  d) None of these

Correct answer is a).
Explanation: pass is a keyword in Python. So, it can’t be a variable.

24). What will be the output of the following Python code?
type(range(10))
  a) <class ‘range’>
  b) int
  c) dict
  d) None of these

Correct answer is a).
Explanation: Range allows to generation a series of numbers within the mentioned range. If it’s used with type(), then it returns <class ‘range’>.

25). What will be the output of the following Python code?
type(‘5’)
  a) <class ‘str’>
  b) <class ‘int’>
  c) <class ‘float’>
  d) None of these

Correct answer is a).
Explanation: As ‘5’ is stored in a string format i.e. inside the colons (”), it will give the output as <class ‘str’>.

Python MCQ Questions (Multiple Choice Quizz)

1. Python Variable Tutorial: A Comprehensive Guide

Python Variable:

Introduction:
Variables are an important concept in any programming language, including Python. In simple language, a variable is a named location in memory that stores a value. In Python, you can use variables to store any type of data, including numbers, strings, and even complex data structures like lists and dictionaries.

Creating Variables in Python:

To create a variable in Python, you need to give it a name and assign a value to it. Here’s an example:
Name = “ Omkar “
Age = 25
Profession = “Software Engineer “
In the example above, we created three variables: Name, Age, and Profession.
The name variable is a string.
The age variable is an integer.
The Profession variable is also a string.

 

Python Variable Naming Rules:

When creating variables in Python, there are a few rules that you need to follow:
1. Variable names must start with a letter or underscore (_), followed by any combination of letters, digits, and underscores.
2. Variable names are case-sensitive, which means name and Name are two different variables.
3. A variable name cannot start with a number.
4. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ).

Python Variable Types:

Python Variable types:
1. Numbers – Consists of integers, floating-point numbers, and complex numbers.
2. Strings – Consists of characters in quotes.
3. Booleans – Consists of True or False values.
4. Lists – Consists of ordered sequences of elements.
5. Tuples – Consists of ordered, immutable sequences of elements.
6. Sets – Consists of unordered collections of unique elements.
7. Dictionaries – Consists of unordered collections of key-value pairs.

Checking types of the variable:
First, we will create some Python variable.
Name = “ Omkar “
Age = 25
Height = 5.8 ft

To check the type of the variable use the type() function.
print(type(Name)) #Output: <class ‘str’>
print(type(Age)) #Output: <class ‘int’>
print(type(Height)) #Output: <class ‘float’>

Python variable assignment types:

Value Assignment:

To assign the value to a Python variable use equal sign ( = ).
Example:
A = 10
We can also assign the same value to multiple Python variables.
A = B = C = 10

Multiple value assignment:

We can assign different values to different Python variables at the same time. We separate the variables and their values by ‘ , ‘.
Example:
a, b, c = 40, 50, 60
Here,
Value of variable a is 40 , b is 50 and c is 60.

Python Variable scope:

Scope of Variable:

In Python, the scope of a variable determines where in the code the variable can be accessed and used. The scope of a variable is defined by where the variable is created and assigned a value.
There are two types of Python variable scopes: global scope and local scope.

1. Global Scope: Variables created outside of any function or class have a global scope. This means that they can be accessed and modified from anywhere in the code, including within functions and classes.
Example:
number = 100 # global Python variable

def print_number():
print(number) # accessing global variable

def modify_number():
global number # declaring number as global variable
number = 200 # modifying global variable

print_number() # Output: 100
modify_number()
print_number() # Output: 200
In the example above, the variable number is declared outside of any function, so it has a global scope. The function print_number() can access and print the value of the number, and the function modify_number() can modify the value of the number by declaring it as a global variable using the global keyword.

2. Local Scope: Variables created inside a function or class have a local scope. This means that they can only be accessed and modified within that function or class.
Example:
def my_function():
number = 100 # local Python variable
print(number) # accessing local variable

my_function() # Output: 100
print(number) # NameError: name ‘number’ is not defined

Basic Mathematical operations using variables:

Creating variables and assigning value to them:
a, b = 10 , 20

Performing operations and printing output:
print(a+b) #Output: 30
print(a-b) #Output: -10
print(a*b) #Output: 200
print(a/b) #Output: 0.5

Variables are an important concept in Python programming language. They allow you to store and manipulate data in your code and are important for writing effective programs. By understanding how to create, name, and use variables, you can write Python code that is easy to read and maintain.

Python Loops Programs, Exercises

1). Write a Python loops program to find those numbers which are divisible by 7 and multiple of 5, between 1500 and 2700 (both included).
Input1:1500
Input2:2700

2). Python Loops program to construct the following pattern, using a nested for loops.
Output :
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*

3). Python Loops program that will add the word from the user to the empty string using python.
Input: “python”
Output : “python”

4). Python Loops program to count the number of even and odd numbers from a series of numbers using python.
Input : (1, 2, 3, 4, 5, 6, 7, 8, 9)
Output :
Number of even numbers: 4
Number of odd numbers: 5

5). Write a program that prints all the numbers from 0 to 6 except 3 and 6 using python.

6). Write a program to get the Fibonacci series between 0 to 20 using python.
Fibonacci Series : 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181

7). Write a program that iterates the integers from 1 to 30 using python. For multiples of three print “Fizz” instead of the number and for multiples of five print “Buzz”.
For numbers that are multiples of both three and five print “FizzBuzz”. 

8). Write a program that accepts a word from the user and converts all uppercases in the word to lowercase using python.
Input : “SqaTOOlS”
Output : “sqatools”

9). Python loops program that accepts a string and calculates the number of digits and letters using python.
Input : “python1234”
Output :
Letters 6
Digits 4

10). Python for loop program to print the alphabet pattern ‘O’ using python.
Output:
  ***  
*       *
*       *
*       *
*       *
*       *
   ***  

11). Python Loops program to print all natural numbers from 1 to n using a while loop in python.

12). Write a program to print all natural numbers in reverse (from n to 1) using a while loop in python.

13). Python Loops program to print all alphabets from a to z using for loop
        Take chr method help to print characters with ASCII values
        chr(65) = ‘A’
        A-Z ASCII Range  65-90
        a-z ASCII Range  97-122

14). Python Loops program to print all even numbers between 1 to 100 in python.

15). Python Loops program to print all odd numbers between 1 to 100 using python.

16). Python Loops program to find the sum of all natural numbers between 1 to n using python.

17). Python program to find the sum of all even numbers between 1 to n using python.

18). Python Loops program to find the sum of all odd numbers between 1 to n using python.

19). Write a program to count the number of digits in a number using python.

20). Write a program to find the first and last digits of a number using python.

21). Write a program to find the sum of the first and last digits of a number using python.

22). Write a program to calculate the sum of digits of a number using python.

23). Write a program to calculate the product of digits of a number using python.

24).Python loops program to enter a number and print its reverse using python.

25). Write a program to check whether a number is a palindrome or not using python loops.

26). Program to find the frequency of each digit in a given integer using Python Loops.

27). Python loops program to enter a number and print it in words.

28). Python loops program to find the power of a number using Python for loop. Take values as an input base number and power, and get the total value using a loop.

29). Python loops program to find all factors of a number using Python. Get all the numbers that can divide this number from 1 to n.
 

30). Write a program to calculate the factorial of a number using Python Loops.

31). Write a program to check whether a number is a Prime number or not using Python Loops.

32). Write a program to print all Prime numbers between 1 to n using Python Loops.

33). Python loops program to find the sum of all prime numbers between 1 to n using Python.

34). Python loops program to find all prime factors of a number using Python Loops.

35). Python loops program to check whether a number is an Armstrong number or not using Python Loops.

Armstrong Example : 153 = 1*1*1 + 5*5*5 + 3*3*3

36). Python loops program to print all Armstrong numbers between 1 to n using Python Loops.

Armstrong Example : 153 = 1*1*1 + 5*5*5 + 3*3*3

37). Write a program to check whether a number is a Perfect number or not using Python.
Get factors of any number and the sum of those factors should be equal to the given number. The factor of 28: 1, 2, 4, 7, 14, and their sum is 28.
38). Python loops program to print all Perfect numbers between 1 to n using Python. The factor of 28: 1, 2, 4, 7, 14, and their sum is 28.
39). Python loops program to print the Fibonacci series up to n terms using Python Loops.
0, 1, 1, 2, 3, 5, 8, 13, 21 …..n

40). Python loops program to print the multiplication table of any number using Python Loops.

41).  Python loops program to print the pattern T using Python Loops.
 
       Output :
 
       * * * * * * * * *
       * * * * * * * * *
               * * *
               * * *
               * * *
               * * *
               * * *
42).  Write a program to print number patterns using Python Loops.
 
     Output:
 
     1
     2   3
     4   5   6
     7   8   9   10
     11  12  13  14  15
     14  13  12  11
     10  9   8
     7   6
     5
43). Write a program to print the pattern using Python Loops.
 
    Output :
 
       *  *  *
    * * * * * *
    * *      * *
    * *      * *
    * * * * * *
    * * * * * *
    * *      * *
    * *      * *
    * *      * *
44). Write a program to print the pyramid structure using Python Loops.
 
    Output:
 
        *
      * * *
    * * * * *
  * * * * * * *
* * * * * * * * *
45). Write a program to count total numbers of even numbers between 1-100 using Python Loops.

Output = 50

46). Write a program to count the total numbers of odd numbers between 1-100 using Python Loops.
Output = 50

47). Write a program to get input from the user if it is a number insert it into an empty list using Python Loops.

Input :
L=[]
125python
Output = [1,2,5]

48). Write a program to get input from the user if it is a string insert it into an empty list using Python Loops.
Input :
L=[]
‘sqatools007’
Output = [‘s’,’q’,’a’,’t’,’o’,’o’,’l’,’s’]

49). Write a program to accept the kilometers covered and calculate the bill according to the following using Python Loops.
First 5 km- 15rs/km
Next 20 km- 12rs/km
After that- 10rs/km

50). Write a program to input electricity unit charges and calculate the total electricity bill according to the given condition using Python Loops.
For the first 50 units Rs. 0.50/unit.
For the next 100 units Rs. 0.75/unit.
For the next 100 units Rs. 1.25/unit.
For units above 250 Rs. 1.50/unit.
An additional surcharge of 17% is added to the bill.
Input = 350
Output = 438.75

51). Write a program to calculate the sum of all odd numbers between 1-100 using Python Loops.

Output = 2500

52). Find the numbers which are divisible by 5 in 0-100 using Python Loops.

53). Write a program to construct the following pattern, using a for loop in Python.
Output :
*
* *
* * *
* * * *
* * * * *

54). Write a program to construct the following pattern, using a for loop in Python.
Output :
* * * * *
* * * *
* * *
* *
*

55). Write a program to construct the following pattern, using a nested for loop in Python.
Output :
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

56). Write a program to get the Fibonacci series between 0 to 10 using Python Loops.
Output = 0 1 1 2 3 5 8 13 21 34 55

57). Write a program to check the validity of password input by users using Python Loops.
At least 1 letter between [a-z] and 1 letter between [A-Z].
At least 1 number between [0-9].
At least 1 character from [$#@].
Minimum length 5 characters.
Maximum length 15 characters.
Input = Abc@1234
Output = Valid password

58). Write a program to check whether a string contains an integer or not using Python Loops.
Input = Python123
Output = True

59). Write a program to print the following pattern using Python Loops.
Output :
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*

60). Write a program to print a table of 5 using for loop using Python Loops.
Output :
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50

61). Write a program to print the first 20 natural numbers using for loop in Python.
Output = 1,2,3,….,20

62). Write a program to display numbers from a list using Python Loops.
Input = [1,5,8,0,4]
Output = 1,5,8,0,4

63). Write a program to print each word in a string on a new line using Python Loops.
Input = Sqatools
Output :
S
q
a
t
o
o
l
s

64). Write a program to create an empty list and add even numbers from 1-10 in it including 10 using Python Loops.
Input = []
Output :
[2,4,6,8,10]

65). Write a program to create an empty list and add odd numbers from 1-10 in it including 1 using Python.
Input = []
Output : [1,3,5,7,9]

66). Write a program to print the keys of a dictionary using Python Loops.
Input = {‘name’:’virat’,’sports’:’cricket’}
Output :
name
cricket

67). Write a program to print the values of the keys of a dictionary using Python.
Input = {name’:’virat’,’sports’:’cricket’}
Output :
Virat
Cricket

68). Write a program to print the keys and values of a dictionary using Python Loops
Input = {name’:’virat’,’sports’:’cricket’}
Output :
name Virat
sports cricket

69). Write a program to print the first 20 natural numbers using a while loop in Python.

70). Write a program to print a table of 2 using a while loop in Python.
Output :
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
2 x 10 = 20

71). Find the sum of the first 10 natural numbers using the while loop in Python Loops.
Output = 55

72). Find the multiplication of the first 10 natural numbers using Python Loops.
Output = 3628800

73). Print numbers from 1-10 except 5,6 using a while loop in Python.
Output :
1
2
3
4
7
8
9
10

74). Write a program to print the days in a week except Sunday using a while loop in Python.
Output :
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday

75). Write a program to find the total number of special characters in a string using Python Loops.
Input = ‘@sqa#tools!!’
Output = 4

76). Write a program to add even numbers in an empty list from a given list using Python Loops.
Input :
A=[2,3,5,76,9,0,16], B=[]
Output = [2,76,0,16]

77). Write a program to add odd numbers in an empty list from a given list using Python Loops.
Input :
A=[3,8,5,0,2,7], B=[]
Output = [3,5,7]

78). Write a program to add special characters in an empty list from a given list using Python Loops.
Input :
A=[s,2,4,6,a,@,!,%,#], B=[]
Output = [@,!,%,#]

79). Write a program to print the last element of a list using a while loop using Python Loops.
Input :
C=[s,q,a,t,o,o,l,s]
Output = s

80). Write a program to print 1-10 natural numbers but it should stop when the number is 6 using a while loop in Python.
Output :
1
2
3
4
5

81). Write a program to print 1-10 natural numbers but it should stop when the number is 6 using Python Loops
Output :
1
2
3
4
5

82). Write a program to count the total number of characters in a file using Python Loops.
Input :
(file.txt
Content= I’m learning python
At
Sqatools)
Output = 26

83). Write a program to find the total number of digits in a file using Python Loops.
Input :
(file.txt – file name
Content-
Virat Kohli scored 100 in the last match)
Output = 3

84). Write a program to find the total number of Uppercase letters in a file using Python Loops.
Input :
(file.txt – file name
Content-
Virat Kohli scored 100 in the last match)
Output = 2

85). Write a program to find the total number of special characters in a file using Python Loops.
Input :
(file.txt – file name
Content-
student@gmail.com
##comment)
Output = 3

86). Write a program to sort a list using for loop in Python Loops. 
Input = [6,8,2,3,1,0,5]
Output = [0,1,2,3,5,6,8]

87). Write a program to add elements from one list to another list and print It in descending order using Python Loops.
Input :
A=[2,5,8,0,1,4], B=[]
Output = [8,5,4,2,1,0]

88). Write a program to find the maximum number from the list using Python Loops
Input : [12,14,45,88,63,97,88]
Output : Maximum number: 97

89). Print the following camel letter pattern using Python Loops.
Output =
A
B C
D E F
G H I J
K L M N O
P Q R S
T U V
W X
Y

90). Print the following small alphabet letter pattern using Python Loops.
Output =
           a
       b c d
     e f g h i
   j k l m n o p
     q r s t u
       v w x
          y

Python List Programs, Exercises

Python list programs help beginners to become experts and the list is one of the most important data structures in Python Programming. Python list can contain any type of data as a member that we can access via positive and negative indexing.

In this article, we have two different sections one for Python list programs for beginners and the second for Python list projects for practice.

python list programs

Python List Programs

1). Python program to calculate the square of each number from the given list.

2). Python program to combine two lists.

3). Python program to calculate the sum of all elements from a list.

4). Python program to find a product of all elements from a given list.

5). Python program to find the minimum and maximum elements from the list.

6). Python program to differentiate even and odd elements from the given list.

7). Python program to remove all duplicate elements from the list.

8). Python program to print a combination of 2 elements from the list whose sum is 10.

9). Python program to print squares of all even numbers in a list.

10). Python program to split the list into two-part, the left side all odd values and the right side all even values.
Input = [5, 7, 2, 8, 11, 12, 17, 19, 22]
Output = [5, 7, 11, 17, 19, 2, 8, 12, 22]

11).  Python program to get common elements from two lists.
Input =
list1 = [4, 5, 7, 9, 2, 1]
list2 = [2, 5, 8, 3, 4, 7]
Outputt : [4, 5, 7, 2]

12). Python program to reverse a list with for loop.

13). Python program to reverse a list with a while loop.

14). Python program to reverse a list using index slicing.

15). Python program to reverse a list with reversed and reverse methods.

16). Python program to copy or clone one list to another list.

17). Python program to return True if two lists have any common member.

18). Python program to print a specific list after removing the 1st, 3rd, and 6th elements from the list.

19). Python program to remove negative values from the list.

20). Python program to get a list of all elements which are divided by 3 and 7.

21). Python program to check whether the given list is palindrome or not. (should be equal from both sides).

22). Python Program to get a list of words which has vowels in the given string.
Input: “www Student ppp are qqqq learning Python vvv”
Output : [‘Student’, ‘are’, ‘learning’, ‘Python’]

23). Python program to add 2 lists with extend method.

24). Python program to sort list data, with the sort and sorted method.

25). Python program to remove data from the list from a specific index using the pop method.

26). Python program to get the max, min, and sum of the list using in-built functions.

27). Python program to check whether a list contains a sublist.

28). Python program to generate all sublists with 5 or more elements in it from the given list.

29). Python program to find the second largest number from the list.
 

30). Python program to find the second smallest number from the list.

31). Python program to merge all elements of the list in a single entity using a special character.
 

32). Python program to get the difference between two lists.

33). Python program to reverse each element of the list.
Input = [‘Sqa’, ‘Tools’, ‘Online’, ‘Learning’, ‘Platform’]
output = [‘aqS’, ‘slooT’, ‘enilno’, ‘gninraeL’, ‘mroftalP’]
34). Python program to combine two list elements as a sublist in a list.
list1 = [3, 5, 7, 8, 9]
list2 = [1, 4, 3, 6, 2]
Output = [[3, 1], [5, 4], [7, 3], [8, 6], [9, 2]]
35). Python program to get keys and values from the list of dictionaries.
Input : [{‘a’:12}, {‘b’: 34}, {‘c’: 23}, {‘d’: 11}, {‘e’: 15}]
Output :  [‘a’, ‘b’, ‘c’, ‘d’, ‘c’]
                [12, 34, 23, 11, 15]

36). Python program to get all the unique numbers in the list.

37). Python program to convert a string into a list.

38). Python program to replace the last and the first number of the list with the word.
Input: [12, 32, 33, 5, 4, 7]
output : [‘SQA’, 32, 33, 5, 4, ‘Tools’]
 

39). Python program to check whether the given element is exist in the list or not.

40). Python program to remove all odd index elements.
Input: [12, 32, 33, 5, 4, 7, 33]
Output: [12,33,4,33]

41). Python program to take two lists and return true if then at least one common member.

42). Python program to convert multiple numbers from a list into a single number.
Input: [12, 45, 56]
Output:124556
43). Python program to convert words of a list into a single string.
Input: [‘Sqa’, ‘Tools’, ‘Best’, ‘Learning’, ‘Platform’]
Output: SqaToolsBestLearningPlatform
44). Python program to print elements of the list separately.
Input: [(‘Black’, ‘Yellow’, ‘Blue’), (50, 55, 60), (30.0, 50.5, 55.66)]
Output:
(‘Black’, ‘Yellow’, ‘Blue’)
(50, 55, 60)
(30.0, 50.5, 55.66)
45). Python program to create a sublist of numbers and their squares from 1 to 10.
Output : [[1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36], [7, 49], [8, 64], [9, 81], [10, 100]]
46). Python program to create a list of five consecutive numbers in the list.
Output : [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]
47). Python program to insert a given string at the beginning of all items in a list.
Input: [1, 2, 3, 4, 5], Sqa
Output: [‘Sqa1’, ‘Sqa2’, ‘Sqa3’, ‘Sqa4’, ‘Sqa5’]
48). Python program to iterate over two lists simultaneously and create a list of sublists.
list1 = [1, 3, 5, 7, 9]
list2 = [8, 6, 4, 2, 10]
output = [[1, 8], [3, 6], [5, 4], [7, 2], [9, 10]]
49). Python program to move all positive numbers on the left side and negative numbers on the right side.
Input: [2, -4, 6, 44, -7, 8, -1, -10]
Output: [2, 6, 44, 8, -4, -7, -1, -10]
50). Python program to move all zero digits to the end of a given list of numbers.
Input: [3, 4, 0, 0, 0, 0, 6, 0, 4, 0, 22, 0, 0, 3, 21, 0]
Output: [3, 4, 6, 4, 22, 3, 21, 0, 0, 0, 0, 0, 0, 0, 0]
51). Python program to find the list in a list of lists whose sum of elements is the highest.
Input: [[11, 2, 3], [4, 15, 6], [10, 11, 12], [7 8, 19]]
Output: [7, 8, 19]
52). Python program to find the items that start with a specific character from a given list.
Input: [‘abbcd’, ‘ppq, ‘abdd’, ‘agr’, ‘bhr’, ‘sqqa’, tools, ‘bgr’]
 
# item starts with a from the given list.
[‘abbcd’, ‘abdd’, ‘agr’]
 
# item starts with b from the given list.
[‘bhr’, ‘bgr’]
 
# item starts with c from the given list.
[]
53). Python program to count empty dictionaries from the given list.
Input: [{}, {‘a’: ‘sqatools’}, [], {}, {‘a’: 123}, {},{},()]
empty_count: 3
54). Python program to remove consecutive duplicates of given lists.
Input: [0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4]
Output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 4]
55). Python program to pack consecutive duplicates of given list elements into sublists.
Input: [0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9]
Output: [[0, 0], [1], [2], [3], [4, 4], [5], [6, 6], [7], [8, 8], [9]]
56). Python program to split a given list into two parts where the length of the first part of the list is given.
Input: [4, 6, 7, 3, 2, 5, 6, 7, 6, 4]
length of the first part is 4
Output: [[4, 6, 7, 3], [2, 5, 6, 7, 6, 4]]
57). Python program to insert items at a specific position in the list.
Input: [2, 4, 6, 8, 3, 22]
Index: 3
Item: 55
Output: [2, 4, 6, 55, 8, 3, 22]
58). Python program to select random numbers from the list.
Input: [1, 4, 5, 7, 3, 2, 9]
Selected 4 random numbers from the list.
59). Python program to create a 3*3 grid with numbers.
Output: [[4, 5, 6], [4, 5, 6], [4, 5, 6]]
60). Python program to zip two lists of lists into a list.
list1: [[1, 3], [5, 7], [9, 11]]
list2: [[2, 4], [6, 8], [10, 12, 14]]
61). Python program to convert the first and last letter of each item from Upper case and lowercase.
Input: [‘Learn’, ‘python’, ‘From’, ‘Sqa’, tools]
Output =
[‘LearN ‘, ‘PythoN ‘, ‘FroM ‘, ‘SqA ‘, ‘ToolS ‘]
[‘learn ‘, ‘python ‘, ‘from ‘, ‘sqa ‘, ‘tools ‘]
62). Python to find maximum and minimum values in the given heterogeneous list.
Input: [‘Sqa’, 6, 5, 2, ‘Tools’]
Output: [6,2]
63). Python program to sort a given list in ascending order according to the sum of its sublist.
Input: [[3, 5, 6], [2, 1, 3], [5, 1, 1], [1, 2, 1], [0, 4, 1]]
            14         6         7           4          5
Output = [[1, 2, 1], [0, 4, 1], [2, 1, 3], [5, 1, 1], [3, 5, 6]]
64). Python program to extract the specified sizes of strings from a given list of string values.
Input: [‘Python’, ‘Sqatools’, ‘Practice’, ‘Program’, ‘test’, ‘list’]
size = 8
Output: [‘Sqatools’, ‘Practice’]
65). Python program to find the difference between consecutive numbers in a given list.
Input list: [1, 1, 3, 4, 4, 5, 6, 7]
Output list: [0, 2, 1, 0, 1, 1, 1]
66). Python program to calculate the average of the given list.
Input : [3, 5, 7, 2, 6, 12, 3]
Output: 5.428571428571429
67). Python program to count integers in a given mixed list.
Input list: [‘Hello’, 45, ‘sqa’,  23, 5, ‘Tools’, 20]
Output: 4
68). Python program to access multiple elements of the specified index from a given list.
Input list: [2, 3, 4, 7, 8, 1, 5, 6, 2, 1, 8, 2]
Index list: [0, 3, 5, 6]
Output: [2, 7, 1, 5]
69). Python program to check whether a specified list is sorted or not.
Input list : [1, 2, 3, 5, 7, 8, 9]
Output: True
 
Input list: [3, 5, 1, 6, 8, 2, 4]
Output: False
70). Python program to remove duplicate dictionaries from a given list.
Input : [{‘name’: ‘john’}, {‘city’: ‘mumbai’}, {‘Python’: ‘laguage’}, {‘name’: ‘john’}]
Output: [{‘city’: ‘mumbai’}, {‘Python’: ‘laguage’}]
71). Python program to check if the elements of a given list are unique or not.
Input: [2, 5, 6, 7, 4, 11, 2, 4, 66, 21, 22, 3]
Output: False
72). Python program to remove duplicate sublists from the list.
Input: [[1, 2], [3, 5], [1, 2], [6, 7]]
Output: [[3, 5],[6, 7]]
73). Python program to create a list by taking an alternate item from the list.
Input: [3, 5, 7, 8, 2, 9, 3, 5, 11]
Output: [3, 7, 2, 3, 11]
74). Python program to remove duplicate tuples from the list.
Input: [(2, 3), (4, 6), (5, 1), (2, 3), (7, 9), (5, 1)]
Output: [(2,3), (4, 6), (5,1), (7, 9)]
75). Python program to insert an element before each element of a list.
Input :[3, 5, 7, 8]
element = ‘a’
Output: [‘a’, 3, ‘a’, 5, ‘a’, 7, ‘a’, 8]
76). Python program to remove the duplicate string from the list.
Input: [‘python’, ‘is’, ‘a’, ‘best’, ‘language’, ‘python’, ‘best’]
Output: [‘python’, ‘is’, ‘a’, ‘best’, ‘language’]

77). Python program to get the factorial of each item in the list.

78). Python program to get a list of Fibonacci numbers from 1 to 20.

79). Python program to reverse all the numbers in a given list.
Input : [123, 145, 633, 654, 254]
Output: [321, 541, 336, 456, 452]
80). Python program to get palindrome numbers from a given list.
Input : [121, 134, 354, 383, 892, 232]
Output : [121, 282, 232]
81). Python program to get a count of vowels in the given list.
Input : [‘Learning’, ‘Python’, ‘From’, ‘SqaTool’]
Output : 8
82). Python program to get the list of prime numbers in a given list.
Input : [11, 8, 7, 19, 6, 29]
Output : [11,  7,  19, 29]
83). Python program to get a list with n elements removed from the left and right.
Input : [2, 5, 7, 9, 3, 4]
Remove 1 element from left
[5, 7, 9, 3, 4]
 
Remove 1 element from the right
[2, 5, 7, 9, 3]
 
Remove 2 elements from left
[7, 9, 3, 4]
 
Remove 2 elements from right
[2, 5, 7, 9]
84). Python program to create a dictionary with two lists.
Input :
list1 : [‘a’, ‘b’, ‘c’, ‘d’, ‘e’]
list2 : [234, 123, 456, 343, 223]
Output: {‘a’: 234, ‘b’: 123, ‘c’: 456, ‘d’: 343, ‘e’: 223}
85). Python program to remove the duplicate item from the list using set.
Input : [2, 5, 7, 8, 2, 3, 4, 12, 5, 6]
Output : [2, 5, 7, 8, 3, 4, 12, 6]
86). Python program to insert a sublist into the list at a specific index.
Input : [4, 6, 8, 2, 3, 5]
sublist, index
[5, 2, 6], 3
Output: [4, 6, 8, [5, 2, 6], 2, 3, 5]
87). Python program to calculate the bill per fruit purchased from a given fruits list.
Input =
Fruit list with Price: [[‘apple’, 30], [‘mango’, 50], [‘banana’, 20], [‘lichi’, 50]]
Fruit with quantity: [[‘apple’, 2]]
Output =
Fruit: Apple
Bill: 60
Fruit: mango
Bill: 500
88). Python program to calculate percentage from a given mark list, the max mark for each item is 100.
Marks_list : [80, 50, 70, 90, 95]
Output: 77%
89). Python program to get the list of all palindrome strings from the given list.
Input: [‘data’, ‘python’, ‘oko’, ‘test’, ‘ete’]
Output: [‘oko’, ‘ete’]
90). Python program to flatten a given nested list structure.
Input: [0, 12, [22, 32], 42, 52, [62, 72, 82], [92, 102, 112, 122]]
Output: [0, 12, 22, 32, 42, 52, 62, 72, 82, 92, 102, 112, 122]
91). Python program to convert tuples in the list into a sublist.
Input: [(3, 5), (6, 8), (8, 11), (12, 14), (17, 23)]
Output: [[3, 5], [6, 8], [8, 11], [12, 14], [17, 23]]
92). Python program to create a dictionary from a sublist in a given list.
Input: [[‘a’, 5], [‘b’, 8], [‘c’, 11], [‘d’, 14], [‘e’, 23]]
Output: {‘a’: 5, ‘b’: 8, ‘c’: 11, ‘d’: 14, ‘e’: 23}
93). Python program to replace ‘Java’ with ‘Python’ from the given list.
Input: [‘Hello’, ‘student’, ‘are’, ‘learning’, ‘Python’, ‘Its’, ‘Python’, ‘Language’]
Output: [‘Hello’, ‘student’, ‘are’, ‘learning’, ‘Java’, ‘Its’, ‘Java’, ‘Language’]
94). Python program to convert the 3rd character of each word to a capital case from the given list.
Input: [‘Hello’, ‘student’, ‘are’, ‘learning’, ‘Python’, ‘Its’, ‘Python’, ‘Language’]
Output: [‘HelLo’, ‘stuDent’, ‘are’, ‘leaRning’, ‘PytHon’, ‘Its’, ‘PytHon’, ‘LanGuage’]
95). Python program to remove the 2nd character of each word from a given list.
Input: [‘Hello’, ‘student’, ‘are’, ‘learning’, ‘Python’, ‘Its’, ‘Python’, ‘Language’]
Output[‘Hllo’, ‘sudent’, ‘ae’, ‘larning’, ‘Pthon’, ‘Is’, ‘Pthon’, ‘Lnguage’]
96). Python program to get a length of each word and add it as a dictionary from the given list.
Input: [‘Hello’, ‘student’, ‘are’, ‘learning’, ‘Python’, ‘Its’, ‘Language’]
Output: [{‘Hello’:5, ‘student’: 7, ‘are’: 3, ‘learning’: 8, ‘Python’: 6, ‘Its’: 3, ‘Language’: 8}]
97). Python program to remove duplicate dictionaries from the given list.
Input: [{‘Hello’:5}, {‘student’: 7}, {‘are’: 3}, {‘learning’: 8}, {‘Hello’:5}, ,{‘Language’: 8}, {‘are’: 3}]
Output: [{‘Hello’:5, ‘student’: 7, ‘are’: 3, ‘learning’: 8, ‘Python’: 6, ‘Its’: 3, ‘Language’: 8}]
98). Python program to decode a run-length encoded given list.
Input: [[2, 1], 2, 3, [2, 4], 5, 1]
Output: [1, 1, 2, 3, 4, 4, 5, 1]
99). Python program to round every number in a given list of numbers and print the total sum of the list.
Input: [22.4, 4.0, -16.22, -9.1, 11.0, -12.22, 14.2, -5.2, 17.5]
Output: 27
 
list1 = [2, 4, 6, 7, 5, 8, 3, 11]

result = [x**2 for x in list1 if x%2 == 0]

print("Result :", result)

Output :

Result : [4, 16, 36, 64]

100).  Python Program to get the Median of all the elements from the list.
list1 = [2, 4, 6, 7, 5, 8, 3, 11]

result = [x**2 for x in list1 if x%2 == 0]

print("Result :", result)

Output :

Result : [4, 16, 36, 64]

101). Python Program to get the Standard deviation of the list element.
102). Python program to convert all numbers to binary format from a given list.
103). Python program to convert all the numbers into Roman numbers from the given list.

Python Lists Project Ideas

1). To-do List: Python list program that allows users to create and manage their to-do lists. Users can add, delete, and update tasks on their list.  Each task can add along with a unique id which will first element of each sub-list through which the user can easily identify the item and task.

2). Shopping List: A program that allows users to create and manage their shopping list. Users can add, delete, and update items on their list. There are many Python list programs listed above those can help user to solve this project.

3). Game Leaderboard: A program that keeps track of scores for multiple players in a game. Use Python lists to store the scores and display a leaderboard of the top players. Nowadays people like to play games and users can apply a basic understanding of Python list programs to write code for this mini-project. 

4). Student Gradebook: A Python list program that allows teachers to enter and manage student grades. Use Python lists and sub-lists to store student names and their corresponding grades.

5). Password Manager: A program that securely stores and manages passwords using Python lists. Users can add, delete, and update passwords, and the program can encrypt the data for added security, Its good exercises to apply understanding Python list programs. 

6). Music Library: A Python list program that allows users to create and manage a music library. Users can add, delete, and update songs, artists, and album details in the list.

7). Recipe Book: A program that allows users to create and manage their recipe book. Users can add, delete, and update recipes, ingredients, and cooking instructions.

8). Contact List: A Python list program that allows users to manage their contact list. Users can add, delete, and update contacts’ names, phone numbers, and email addresses in the list.

9). Movie Library: A Python list program that allows users to create and manage a movie library. Users can add, delete, and update movies, actors, and directors in the list.

10). Sports Team Roster: A program that allows coaches to manage their sports team roster. Coaches can add, delete, and update players’ names, positions, and statistics in the list.

Official reference for python list data structure