CS: Introduction to Python Flashcards
What’s an interpreter?
An interpreter is a translator that takes a high-level language (source program) and converts it into machine code.
What are some important things to keep in mind about programming in Python?
Python is case sensitive, spacing is important, and error messages are helpful in helping you learn.
What’s a variable?
It’s a container in which data can be stored.
What will be the output?
x=4
x=”Noura”
print(x)
Noura
What are the rules for python variables?
- A variable name must start with a letter or underscore.
- A variable name cannot start with a number
- A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
- Variable names are case-sensitive
- The reserved words (keywords) cannot be used naming the variable.
What are a few reserved keywords?
False, None, True, and, if, elif, else, not, or, while…
Can I name my variable “2Names”?
No, because variables can’t start with numbers.
Can I name my variable “_2Names”?
Yes, because variables can start with underscores.
Is this a valid way of assigning variables?
x, y, z = “A”, “B”, “C”
Yes
What are the different data types?
String (str), integer (int), float (float), boolean (bool), lists…
(Program) Create variables that input the user’s name, height, and citizenship status.
name = input(“Enter your name: “)
height = float(input(“Enter your height in meters: “))
citizenship_status = input(“Are you a citizen? (yes/no): “)
print(“User Information:”)
print(“Name:”, name)
print(“Height:”, height, “meters”)
print(“Citizenship Status:”, citizenship_status)
What is type casting?
Changing one variable data type into another.
ex: Age=int(Age)