0% found this document useful (0 votes)
8 views8 pages

Python Programming Basics Explained

Uploaded by

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

Python Programming Basics Explained

Uploaded by

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

Python viva

Why is Python popular?


What is Python?
Because it is simple, readable, and works
Python is a high-level, interpreted, for many fields (web, AI, data, automation).
general-purpose programming language
known for its readability and simplicity. Is Python case-sensitive?

Who developed Python? Yes.

Guido van Rossum, released in 1991. What is a program?

Why is Python called an A set of instructions that a computer can


interpreted language? follow.

Because Python code is executed What is a script?


line-by-line by the Python interpreter.
A small program written to automate tasks.
What are Python identifiers?
What is an interpreter?
Names given to variables, functions,
classes, etc. A program that runs code line by line.

What are keywords in Python? Is Python compiled or interpreted?


Reserved words that have special meaning Interpreted.
(e.g., if, for, while, class, return).
What is indentation?
What are variables?
Spaces at the beginning of a line.
Containers that store data values.
Why is indentation important in
What are data types in Python? Python?
Int,float,str,bool,list,tuple, It defines code blocks.

set,dict,NoneType What happens if indentation is


incorrect?
8. What is type conversion?
Python gives an IndentationError.
Changing data type:
What is a comment?
●​ Implicit: done automatically​
A note in code ignored by Python.
●​ Explicit: using functions like int(),
str(), float()
Python viva
How to write a single-line Examples of invalid identifiers:
comment?
1name, my-name, class (keyword), total
Using #. marks (space).

How to write a multi-line Rules to write identifiers:


comment?
●​ Can contain letters, digits,
Using triple quotes: underscore​

""" ●​ Cannot start with a digit​


This is a comment
●​ No spaces​
"""
●​ Cannot use keywords​
What is print()?
●​ Case-sensitive​
A function that displays output.

Can Python execute without What is a variable?


semicolons?
A name that stores a value.
Yes.
How to declare a variable?
What is an error?
Just assign a value:
A problem that stops the program.
x = 10
What are syntax errors?
Errors in grammar of the code. Can variable types change in
Python?
What are runtime errors?
Yes.
Errors that occur while the program is
running. What is dynamic typing?
What is an identifier? Variables can change type at runtime.

A name given to variables, functions, What is a constant?


classes, etc.
A value that should not change.
Examples of valid identifiers:
Does Python have constants?
name, age1, _value, total_marks.
No official constants, but by convention
uppercase is used: PI = 3.14.
Python viva
What are Python keywords? What is complex?
Reserved words with special meaning. Numbers with a real and imaginary part
(e.g., 3+4j).
How many keywords are there in
Python? How to check data type?
type(x)
Around 35+ (varies by version).

Give 5 examples of keywords. What is type casting?


if, else, for, while, class. Changing one data type to another.

Can keywords be used as variable Difference between implicit and


names? explicit casting.
No. ●​ Implicit: Python converts
automatically.​
What is the keyword pass?
●​ Explicit: Programmer converts
A placeholder that does nothing. manually using int(), float(),
etc.
What is a data type?
What is an operator?
Type of value stored in a variable.
A symbol that performs an operation.
What is integer?
Types of operators:
Whole numbers (e.g., 10, -5).
Arithmetic, relational, logical, assignment,
What is float? bitwise, membership, identity.

Decimal numbers (e.g., 3.14). What is arithmetic operator?

What is boolean? Used for math: + - * / % // **.

True or False. What is relational operator?


What are strings? Compares values: > < >= <= == !=.

Text inside quotes. What is a logical operator?


What is None? and, or, not.

Represents “no value”.


Python viva
What is assignment operator? What is a string?

Assign values: = += -= *=. A sequence of characters.

What is bitwise operator? How to create a string?

Works on bits: & | ^ ~ << >>. Using quotes: "hello" or 'hello'.

What is membership operator? Are strings mutable?

Checks membership: in, not in. No, they are immutable.

What is identity operator? What is indexing?

Checks object identity: is, is not. Accessing characters by position.

What is operator precedence? What is negative indexing?

Defines order in which operators are Indexing from end: -1 for last character.
evaluated.
What is slicing?
How to take input from user?
Extracting part of a string:
Using input().
s[1:4]
What is the input() function?
String concatenation?
Reads user input as a string. "Hello" + "World"

How to print without newline? String repetition?


print("Hello", end="") "Hi" * 3

How to format strings? len() function?


Using f-strings, .format(), or %. Returns length of string.

What is f-string? Difference between isalpha() and


isdigit():
Formatted string using f:
●​ isalpha() → letters
f"Name = {name}" only/alphabets only​

●​ isdigit() → digits only​


Python viva
What is a list? How to reverse a list?
[Link]()
An ordered collection of items.

Are lists mutable? What is a tuple?


An ordered collection of items.
Yes.

How to create a list?


l = [1, 2, 3] Are tuples mutable or immutable?
Immutable.
How to access list elements?
How to create a tuple?
Using indexes: l[0]. t = (1, 2, 3)

List slicing?
l[1:4] Why use tuples?
They are faster and protect data from
changes.
Append vs extend?
●​ append: adds one item​ Can a tuple contain different data
types?
●​ extend: adds multiple items​
Yes.

Remove vs pop? What is a set?


●​ remove(x): removes value​ An unordered collection of unique items.

●​ pop(i): removes index​ Are sets ordered?


No.
Difference between list and array?
Do sets allow duplicates?
Lists store different data types; arrays store
the same type (in array module). No.

How to add an element in a set?


How to sort a list? [Link](5)

[Link]()
How to remove an element?
[Link](5)
Python viva
How to get all values?
[Link]()
Set union?
a | b
What is items()?

Set intersection? Returns key-value pairs.


a & b
What is decision making?
Choosing actions based on conditions.
Difference between remove and
discard? What is if statement?
●​ remove: error if element not found​ Executes code if condition is true.
●​ discard: no error
What is elif?
What is a dictionary? Additional condition.
A collection of key-value pairs.
What is nested if?
What are keys and values? if inside another if.
Key = identifier, Value = data.
What is a loop?
Are dictionary keys unique? Repeats code.
Yes.
Types of loops in Python.
Can a dictionary key be a list? for and while.
No (lists are mutable).
Difference between for and while
How to add a new key-value pair? loop.
d["age"] = 20 for → known range​
while → runs until condition becomes
false
How to delete a key?
del d["age"] What is infinite loop?
A loop that never ends.
How to get all keys?
[Link]()
What is break?
Python viva
Stops the loop. What are variable-length
arguments?
What is continue?
Arguments that accept many values.
Skips current iteration.
What is args?
What is pass?
Stores variable number of positional
Does nothing. arguments.

What is a function? What are kwargs?


Block of code that performs a task. Stores variable number of keyword
arguments.
How to define a function?
def func():
pass What is a recursive function?
A function that calls itself.
What is a return statement?
What is the lambda function?
Send a value back.
Small anonymous function.
What is the parameter?
What is a module?
Variable inside function definition.
A Python file.
What is the argument?
What is a package?
Value passed to function.
A folder containing modules.
Difference between parameter and
argument: How to import a module?
import math
Parameter = in definition, Argument = in
call.

What are default arguments? Difference between import and


from-import:
Arguments with default values.
●​ import math → use
What are keyword arguments? [Link]()​

Arguments passed using names. ●​ from math import sqrt → use


sqrt()​
Python viva
What is a math module? How to check if a file exists?
import os
Provides mathematical functions.
[Link]("[Link]")
What is a random module?
What is an exception?
Used for random numbers.
An error that can be handled.
What is the datetime module?
Difference between error and
Used for date and time. exception:

What is file handling? Error = serious issue​


Exception = can be caught.
Working with files (read/write).
What is try-except?
Used to handle exceptions.
How to open a file?
What is finally?
open("[Link]")
Block that always executes.
File modes in Python:
What is raise?
r, w, a, rb, wb.
Used to manually throw an exception.
How to read a file?
[Link]() What is ZeroDivisionError?
Error when dividing by zero.
How to write to a file?
What is TypeError?
[Link]("hello")
Error for wrong data type.

What is with open()? What is IndexError?


Automatically closes file. Error for invalid index.

Difference between read and What is NameError?


readline:
Error when variable is not defined.
●​ read() → whole file​

●​ readline() → one line​

You might also like