Python Flashcards

1
Q

What are the key features of Python?

A
  • Simple and easy to learn syntax
  • Interpreted language with high-level data structures
  • Extensive standard library
  • Open-source with a large and active community
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

differences between Python 2 and Python 3

A
  • Print statement: In Python 2, print is a statement, while in Python 3, it’s a function.
  • Unicode support: Python 3 handles strings as Unicode by default, whereas Python 2 treats strings as ASCII by default.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

data types available in Python?

A
  • Basic: int, float, str, bool, list, tuple, set, dict
  • Other data types: complex, bytes, bytearray, None
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain the difference between == and is in Python.

A

== is the equality operator used to compare the values of two objects.

is is the identity operator used to check if two variables refer to the same object in memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the difference between range() and xrange() in Python 2?

A

range() returns a list of numbers
xrange() returns an xrange object which behaves like an iterator and generates numbers on the fly.

xrange() is more memory efficient when dealing with large ranges as it generates numbers on demand rather than creating a list of all the numbers upfront.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the purpose of the __init__ method in Python classes?

A
  • used for initializing newly created objects
  • It gets called automatically when a new instance of a class is created.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly