1/49
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What is Python?
An interpreted, high-level, dynamically-typed programming language known for its readability and ease of use.
What are Python’s key features?
Interpreted, dynamically-typed, object-oriented, open-source, extensive libraries, multi-paradigm programming.
How do you declare a variable in Python?
Use the syntax x = value, e.g., x = 10 or name = 'Alice'.
What is the difference between = and == in Python?
'=' is an assignment operator; '==' is a comparison operator.
What data types are available in Python?
int, float, complex, bool, str, list, tuple, set, dict, NoneType.
How do you check the data type of a variable?
Use the type() function, e.g., type(x).
How do you take user input in Python?
Use the input() function, e.g., name = input('Enter your name: ').
What is type casting?
Converting one data type into another, e.g., int('10') converts string to integer.
How do you perform string concatenation?
Use the '+' operator, e.g., full_name = first_name + ' ' + last_name.
What is the difference between is and ==?
'is' checks object identity; '==' checks value equality.
How do you write an if-else statement in Python?
if x > 0: print('Positive') else: print('Negative').
How do you write a for loop?
for i in range(5): print(i).
How do you write a while loop?
while x < 5: print(x); x += 1.
What is the difference between break and continue?
'break' exits the loop; 'continue' skips the current iteration.
How do you use the pass statement?
A placeholder for future code, e.g., if x > 0: pass.
How do you define a function in Python?
Use the def keyword, e.g., def greet(name): return 'Hello ' + name.
What is a default parameter in a function?
A parameter with a default value, e.g., def greet(name='Guest').
What is the difference between return and print in a function?
'return' sends a value back; 'print' displays it.
What are *args and kwargs in functions?
*args allows for variable-length arguments; **kwargs allows for keyword arguments.
What is recursion?
A function that calls itself, e.g., factorial function.
How do you create a list?
Use square brackets, e.g., my_list = [1, 2, 3, 4, 5].
How do you add an element to a list?
Use my_list.append(value).
How do you remove an element from a list?
Use my_list.remove(value) to remove the first occurrence.
What is the difference between a tuple and a list?
Tuples are immutable; lists are mutable.
How do you create a dictionary?
Use curly braces, e.g., my_dict = {'name': 'Alice', 'age': 25}.
How do you access a dictionary value?
Use my_dict['key'], e.g., my_dict['name'].
How do you add a key-value pair to a dictionary?
Use my_dict['key'] = value.
How do you get the length of a string?
Use len(string), e.g., len('hello').
How do you convert a string to uppercase?
Use string.upper(), e.g., 'hello'.upper().
How do you split a string?
Use string.split(), e.g., 'hello world'.split().
How do you read a file in Python?
Use with open('filename', 'r'): to read the content.
How do you write to a file?
Use with open('filename', 'w'): to write content.
How do you define a class?
Use the class keyword, e.g., class Person: def init(self, name): self.name = name.
What is self in Python classes?
Represents the instance of the class.
How do you create an object of a class?
Instantiate the class, e.g., p = Person('Alice').
What is inheritance in Python?
A mechanism where a new class derives from an existing class.
What is method overriding?
A child class providing a specific implementation of a method already defined in its parent class.
How do you handle exceptions in Python?
except: . What is the purpose of the finally block?
Executes code regardless of whether an exception occurs.
What is a lambda function?
An anonymous function defined by the lambda keyword, e.g., square = lambda x: x * x.
What is list comprehension?
A concise way to create lists, e.g., squares = [x*x for x in range(10)].
How do you sort a list in Python?
Use sorted() function, e.g., sorted(my_list).
What is a generator in Python?
A function that yields values using the yield statement.
How do Python and Java interact?
They can communicate via subprocesses, Jython, Py4J, or shared files and APIs.
How can Java run a Python script?
Using ProcessBuilder, e.g., ProcessBuilder pb = new ProcessBuilder('python', 'script.py').
How can Python call a Java method?
Using Py4J to call Java methods.
What is Jython?
Jython allows running Python inside the Java Virtual Machine (JVM).
How can Python and Java share data?
Using JSON, databases, REST APIs, or sockets.
Why would you use both Java and Python?
Java for performance-intensive applications; Python for scripting and AI.
Which is better: Java or Python?
It depends on the use case: Java for speed, Python for flexibility.