Python Basics — Variables, Data Types & Print
Every Python interview for a data analyst role starts with these. Know your data types cold — interviewers use these to filter out candidates who have only watched tutorials without writing code.
What are the main data types in Python?
int, float, str, bool, list, tuple, dict, setFor data analytics, you will mostly work with int and float (numbers), str (text/column names), bool (True/False filters), list and dict (structured data). Know which is mutable and which is not.
What is the difference between int and float?
x = 10 # int — whole number
y = 10.5 # float — decimal number
type(x) # <class "int">
type(y) # <class "float">When you read a CSV with Pandas, numeric columns with decimals become float64, whole numbers become int64. Knowing this helps you debug dtype errors.
How do you check the type of a variable?
x = 42
print(type(x)) # <class "int">
df["salary"].dtype # in Pandas — dtype("int64")type() is for plain Python objects. In Pandas, use .dtype on a Series or .dtypes on a DataFrame to check column types before transformations.
What is the difference between = and == in Python?
x = 10 # assignment — stores value in variable
x == 10 # comparison — returns True or FalseUsing = when you meant == inside a condition causes a SyntaxError in Python (unlike some languages). This catches beginners. In Pandas: df[df["age"] == 25] — always ==.
How do you convert a string "123" to an integer?
s = "123"
n = int(s) # 123
f = float(s) # 123.0Type conversion is common when reading data from CSVs or APIs where numbers arrive as strings. Pandas usually handles this automatically, but manual conversion is needed for edge cases.
What does the print() function do and how do you format output?
name = "Priya"
age = 25
print(f"Name: {name}, Age: {age}") # f-string (preferred)
print("Name: {}, Age: {}".format(name, age)) # .format()f-strings (Python 3.6+) are the cleanest way to format output. In data analysis you use them for logging results, printing summaries, and building dynamic report messages.
EVIKA ACADEMY · PYTHON FOR DATA ANALYTICS
Want to master Python with live practice?
Join our Python for Data Analysis course — live classes in Noida and online across India.
Book Free Demo Class →