Data Science & ML

Python Basics

Variables, data types, control structures, functions, modules, exceptions

25 interview questionsยท
Junior
1

What is a variable in Python?

Answer

A variable in Python is a name that refers to a memory location containing a value. Unlike other languages, Python uses dynamic typing: the variable type is automatically determined during assignment. There is no need to explicitly declare the type.

2

What is the type of the value 3.14 in Python?

Answer

In Python, 3.14 is a floating-point number, so it is of type float. Integers (without decimals) are of type int, while numbers with a decimal part are automatically considered float. The type() function can be used to check a value's type.

3

How to convert the string "42" to an integer in Python?

Answer

The int() function converts a string representing a number to an integer. This operation is called casting or type conversion. If the string does not represent a valid number, a ValueError will be raised. There is also float() for decimals and str() for strings.

4

What is the difference between a list and a tuple in Python?

5

What does the expression bool("") return in Python?

+22 interview questions

Master Data Science & ML for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free