Intro to Functions and Variables in 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/285

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 2:02 AM on 5/30/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

286 Terms

1
New cards

What is a function in Python?

A reusable block of code designed to perform a specific task.

2
New cards

What is the basic purpose of print()?

print() displays information on the screen.

3
New cards

Write the code to print hello, world

print("hello, world")

4
New cards

What is a side effect?

When a function changes or affects something outside of itself, like print() displaying text on the screen.

5
New cards

Why does print("hello") have a side effect?

because it outputs text/string to the terminal.

6
New cards

What does it mean to call a function?

To run or use the function by writing its name followed by parentheses.

7
New cards

What is wrong with writing print without parentheses?

it does not call the function

8
New cards

Write the code to call the print function with no arguments

print()

9
New cards

What are parentheses used for when calling a function?

They tell Python to run the function.

10
New cards

What is an argument?

The information or value you give to a function.

11
New cards

In print("hello, world"), what is the argument?

"hello, world"

12
New cards

What is the general structure for calling a function with an argument?

function(argument)

13
New cards

In print("hello, world"), what is the function?

print

14
New cards

In print("hello, world"), what is the argument?

"hello, world"

15
New cards

What do quotation marks tell Python?

They tell Python that the content is text, also called a string.

16
New cards

What is a string?

Text surrounded by quotation marks.

17
New cards

What is the Python type name for a string?

str

18
New cards

Give an example of a string

"hello"

19
New cards

Can strings use single quotes?

Yes, for example 'hello'

20
New cards

Can strings use double quotes?

Yes, for example "hello"

21
New cards

Write code to print the string Saihaj

print("Saihaj")

22
New cards

What happens when Python runs print("hello, world")?

Python calls print(), reads the string argument, and displays hello, world.

23
New cards

What is the output of print("hello, world")?

hello, world

24
New cards

Do words/text need quotation marks in Python?

Yes, text needs quotation marks so Python treats it as a string.

25
New cards

Write code to print the string hello

print("hello")

26
New cards

Why would print(hello) cause an error if hello was never defined?

Because Python thinks hello is a variable name, not text.

27
New cards

Do numbers need quotation marks in Python?

No, numbers can be written directly.

28
New cards

Write code to print the number 5

print(5)

29
New cards

What is the difference between 5 and "5"?

5 is treated as an integer, while "5" is treated text/a string

30
New cards

What is the output of print(5 + 5)?

10

31
New cards

What is the output of print("5" + "5")?

55

32
New cards

Why does print("5" + "5") output 55 instead of 10?

Because Python joins the two strings instead of doing math.

33
New cards

How do you give print() multiple arguments?

Separate the arguments with commas.

34
New cards

Write code to print hello and world as two separate arguments

print("hello", "world")

35
New cards

What is the output of print("hello", "world")?

hello world

36
New cards

Write code to print Age: and 18 as separate arguments

print("Age:", 18)

37
New cards

What is the output of print("Age:", 18)?

Age: 18

38
New cards

Can variables be used as arguments?

Yes, variables can be passed into functions as arguments.

39
New cards

Write code that stores "Saihaj" in a variable called name

name = "Saihaj"

40
New cards

Write code that stores 18 in a variable called age

age = 18

41
New cards

Write code to print the value stored in name

print(name)

42
New cards

Write code to print My name is and then the variable name

print("My name is", name)

43
New cards

What are the three main types of print arguments from the notes?

String arguments, integer arguments, and variable arguments.

44
New cards

What is a bug?

A defect or error in a computer program caused by a mistake in the code.

45
New cards

What is debugging?

Finding and correcting errors in code.

46
New cards

What does the terminal command python hello.py do?

It uses Python to run the file named hello.py.

47
New cards

What does python mean in the command python hello.py?

It tells the terminal to use the Python program.

48
New cards

What does hello.py mean in the command python hello.py?

It is the Python file you want to run.

49
New cards

What does the .py file ending mean?

It means the file is a Python file.

50
New cards

Write the correct terminal command to run hello.py

python hello.py

51
New cards

If hello.py contains print("hello, world"), what appears after running python hello.py?

hello, world

52
New cards

What does input() do?

It shows a prompt, waits for the user to type something, and returns what the user typed.

53
New cards

Write code to ask the user What is your name?

input("What is your name? ")

54
New cards

What is a prompt in input()?

The message shown to the user inside input().

55
New cards

In input("Enter your age: "), what is the prompt?

"Enter your age: "

56
New cards

What is a variable?

A name that stores a value so you can use it later.

57
New cards

In name = "Saihaj", what is the variable name?

name

58
New cards

In name = "Saihaj", what is the value?

"Saihaj"

59
New cards

What does = mean in Python?

It is the assignment operator, meaning assign the value on the right to the variable on the left.

60
New cards

What is the assignment operator?

=

61
New cards

Write code to store "Hello" in a variable called hello

hello = "Hello"

62
New cards

Write code to store "Saihaj" in a variable called name

name = "Saihaj"

63
New cards

Write code to print hello and name as two variables

print(hello, name)

64
New cards

If hello = "Hello" and name = "Saihaj", what is the output of print(hello, name)?

Hello Saihaj

65
New cards

What is a comment?

A note in code that Python ignores.

66
New cards

What symbol creates a single-line comment in Python?

#

67
New cards

Write a comment that says This prints a greeting

This prints a greeting

68
New cards

Does Python run comments?

No, Python ignores comments.

69
New cards

Why are comments useful?

They explain what the code does for humans reading it.

70
New cards

Write code with a comment after it that stores the user's name

name = "Saihaj" # stores the user's name

71
New cards

Write code with a comment after it that prints name

print(name) # prints the value of name

72
New cards

What are triple quotes sometimes used for?

Longer notes or multi-line comments, though # is more common for regular comments.

73
New cards

Write a triple-quoted note

"""This is a longer note."""

74
New cards

What is pseudocode?

A way to plan code using normal language instead of real Python syntax.

75
New cards

Is pseudocode meant to be run by Python?

No, it is meant to help you plan the program.

76
New cards

Why is pseudocode useful?

It helps you think through the steps before writing real code.

77
New cards

Write pseudocode for asking the user for their name

Ask the user for their name

78
New cards

Write pseudocode for storing a name in a variable

Store the answer in a variable called name

79
New cards

Write pseudocode for printing a greeting

Print a greeting using their name

80
New cards

What are parameters?

The options or variables listed in a function definition or documentation.

81
New cards

What does objects mean in print(*objects, sep=' ', end='\n', file=None, flush=False)?

The things you want to print.

82
New cards

What does the * in *objects mean?

It means print() can accept more than one object.

83
New cards

What does sep mean in print()?

Separator; it controls what goes between multiple printed objects.

84
New cards

What is the default sep value in print()?

A space.

85
New cards

What is the output of print("Hello", "Saihaj")?

Hello Saihaj

86
New cards

Write code to print Hello and Saihaj with a dash between them

print("Hello", "Saihaj", sep="-")

87
New cards

What is the output of print("Hello", "Saihaj", sep="-")?

Hello-Saihaj

88
New cards

What does end mean in print()?

It controls what happens at the end of the printed line.

89
New cards

What is the default end value in print()?

\n, which means new line.

90
New cards

What does \n mean?

New line.

91
New cards

What is the output of print("Hello") followed by print("World") on the next line?

Hello and World appear on separate lines.

92
New cards

Write code so Hello and World print on the same line with a space between them

print("Hello", end=" "); print("World")

93
New cards

What does file=None control in print()?

Where the output goes; by default, it prints to the screen.

94
New cards

What does flush=False control in print()?

Whether Python immediately forces the output to appear.

95
New cards

Do most beginner programs need to change file or flush?

No.

96
New cards

What is an escape character?

A backslash sequence that lets you put special characters inside a string.

97
New cards

What symbol starts an escape character?

98
New cards

What does \n do inside a string?

Creates a new line.

99
New cards

Write code to print Hello and World on separate lines using \n

print("Hello\nWorld")

100
New cards

What does \t do inside a string?

Creates a tab space.