Python

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/49

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 1:20 AM on 2/7/25
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

50 Terms

1
New cards

What is Python?

An interpreted, high-level, dynamically-typed programming language known for its readability and ease of use.

2
New cards

What are Python’s key features?

Interpreted, dynamically-typed, object-oriented, open-source, extensive libraries, multi-paradigm programming.

3
New cards

How do you declare a variable in Python?

Use the syntax x = value, e.g., x = 10 or name = 'Alice'.

4
New cards

What is the difference between = and == in Python?

'=' is an assignment operator; '==' is a comparison operator.

5
New cards

What data types are available in Python?

int, float, complex, bool, str, list, tuple, set, dict, NoneType.

6
New cards

How do you check the data type of a variable?

Use the type() function, e.g., type(x).

7
New cards

How do you take user input in Python?

Use the input() function, e.g., name = input('Enter your name: ').

8
New cards

What is type casting?

Converting one data type into another, e.g., int('10') converts string to integer.

9
New cards

How do you perform string concatenation?

Use the '+' operator, e.g., full_name = first_name + ' ' + last_name.

10
New cards

What is the difference between is and ==?

'is' checks object identity; '==' checks value equality.

11
New cards

How do you write an if-else statement in Python?

if x > 0: print('Positive') else: print('Negative').

12
New cards

How do you write a for loop?

for i in range(5): print(i).

13
New cards

How do you write a while loop?

while x < 5: print(x); x += 1.

14
New cards

What is the difference between break and continue?

'break' exits the loop; 'continue' skips the current iteration.

15
New cards

How do you use the pass statement?

A placeholder for future code, e.g., if x > 0: pass.

16
New cards

How do you define a function in Python?

Use the def keyword, e.g., def greet(name): return 'Hello ' + name.

17
New cards

What is a default parameter in a function?

A parameter with a default value, e.g., def greet(name='Guest').

18
New cards

What is the difference between return and print in a function?

'return' sends a value back; 'print' displays it.

19
New cards

What are *args and kwargs in functions?

*args allows for variable-length arguments; **kwargs allows for keyword arguments.

20
New cards

What is recursion?

A function that calls itself, e.g., factorial function.

21
New cards

How do you create a list?

Use square brackets, e.g., my_list = [1, 2, 3, 4, 5].

22
New cards

How do you add an element to a list?

Use my_list.append(value).

23
New cards

How do you remove an element from a list?

Use my_list.remove(value) to remove the first occurrence.

24
New cards

What is the difference between a tuple and a list?

Tuples are immutable; lists are mutable.

25
New cards

How do you create a dictionary?

Use curly braces, e.g., my_dict = {'name': 'Alice', 'age': 25}.

26
New cards

How do you access a dictionary value?

Use my_dict['key'], e.g., my_dict['name'].

27
New cards

How do you add a key-value pair to a dictionary?

Use my_dict['key'] = value.

28
New cards

How do you get the length of a string?

Use len(string), e.g., len('hello').

29
New cards

How do you convert a string to uppercase?

Use string.upper(), e.g., 'hello'.upper().

30
New cards

How do you split a string?

Use string.split(), e.g., 'hello world'.split().

31
New cards

How do you read a file in Python?

Use with open('filename', 'r'): to read the content.

32
New cards

How do you write to a file?

Use with open('filename', 'w'): to write content.

33
New cards

How do you define a class?

Use the class keyword, e.g., class Person: def init(self, name): self.name = name.

34
New cards

What is self in Python classes?

Represents the instance of the class.

35
New cards

How do you create an object of a class?

Instantiate the class, e.g., p = Person('Alice').

36
New cards

What is inheritance in Python?

A mechanism where a new class derives from an existing class.

37
New cards

What is method overriding?

A child class providing a specific implementation of a method already defined in its parent class.

38
New cards

How do you handle exceptions in Python?

Use try-except blocks, e.g., try: except: .
39
New cards

What is the purpose of the finally block?

Executes code regardless of whether an exception occurs.

40
New cards

What is a lambda function?

An anonymous function defined by the lambda keyword, e.g., square = lambda x: x * x.

41
New cards

What is list comprehension?

A concise way to create lists, e.g., squares = [x*x for x in range(10)].

42
New cards

How do you sort a list in Python?

Use sorted() function, e.g., sorted(my_list).

43
New cards

What is a generator in Python?

A function that yields values using the yield statement.

44
New cards

How do Python and Java interact?

They can communicate via subprocesses, Jython, Py4J, or shared files and APIs.

45
New cards

How can Java run a Python script?

Using ProcessBuilder, e.g., ProcessBuilder pb = new ProcessBuilder('python', 'script.py').

46
New cards

How can Python call a Java method?

Using Py4J to call Java methods.

47
New cards

What is Jython?

Jython allows running Python inside the Java Virtual Machine (JVM).

48
New cards

How can Python and Java share data?

Using JSON, databases, REST APIs, or sockets.

49
New cards

Why would you use both Java and Python?

Java for performance-intensive applications; Python for scripting and AI.

50
New cards

Which is better: Java or Python?

It depends on the use case: Java for speed, Python for flexibility.

Explore top notes

note
APUSH Unit 4
Updated 693d ago
0.0(0)
note
Unit 3 : Macromolecules
Updated 330d ago
0.0(0)
note
AP Gov Ch. 1 and 2
Updated 394d ago
0.0(0)
note
Oceans and Coastal Margins
Updated 687d ago
0.0(0)
note
2024Chem. IMFs ↓↑
Updated 593d ago
0.0(0)
note
PROTEINS!1!!1!1!!!!!
Updated 1099d ago
0.0(0)
note
APUSH Unit 4
Updated 693d ago
0.0(0)
note
Unit 3 : Macromolecules
Updated 330d ago
0.0(0)
note
AP Gov Ch. 1 and 2
Updated 394d ago
0.0(0)
note
Oceans and Coastal Margins
Updated 687d ago
0.0(0)
note
2024Chem. IMFs ↓↑
Updated 593d ago
0.0(0)
note
PROTEINS!1!!1!1!!!!!
Updated 1099d ago
0.0(0)

Explore top flashcards

flashcards
civil war
25
Updated 1239d ago
0.0(0)
flashcards
Units 10-12 Book Units
36
Updated 433d ago
0.0(0)
flashcards
Chapter 11 Exam
32
Updated 1157d ago
0.0(0)
flashcards
Tourism and Travel Vocabulary
60
Updated 284d ago
0.0(0)
flashcards
high five unit 1, 2, 3, 4
100
Updated 1205d ago
0.0(0)
flashcards
civil war
25
Updated 1239d ago
0.0(0)
flashcards
Units 10-12 Book Units
36
Updated 433d ago
0.0(0)
flashcards
Chapter 11 Exam
32
Updated 1157d ago
0.0(0)
flashcards
Tourism and Travel Vocabulary
60
Updated 284d ago
0.0(0)
flashcards
high five unit 1, 2, 3, 4
100
Updated 1205d ago
0.0(0)