Search Header Logo

Mastering Python Basics

Authored by Dumbani Tunthuwa

Computers

12th Grade

Used 1+ times

Mastering Python Basics
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

20 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the correct way to declare a variable in Python?

var x: int = 5

x = 5

x := 5

let x = 5

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How do you assign a value to a variable in Python?

Assign values using the '->' operator.

Variables are assigned values by enclosing them in parentheses.

Use the '=' operator to assign a value to a variable.

Use the '==' operator to assign a value to a variable.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Define a function in Python and provide an example of how to call it.

def greet(name): return f'Hello, {name}!' # Example of calling the function: print(greet('Alice'))

greet(name): print('Greetings, ' + name)

def greet(): return 'Hello!'

def hello(name): return 'Hi, ' + name

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the output of the following code: print('Hello' + ' World')?

Hello World

Hello, World

Hello World!

HelloWorld

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How do you access the first character of a string in Python?

s[1]

s.first()

s.get(0)

s[0]

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is string slicing and how is it used in Python?

String slicing is used to convert a string to uppercase in Python.

String slicing allows you to replace characters in a string directly in Python.

String slicing is a method to concatenate two strings in Python.

String slicing is a method to extract parts of a string using the syntax string[start:end:step] in Python.

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Explain type casting in Python with an example.

Example: num_str = '123'; num_int = int(num_str); # num_int is now an integer 123

Example: num_list = [1, 2, 3]; num_str = str(num_list); # num_str is now a string '[1, 2, 3]'

Example: num_float = 123.45; num_str = str(num_float); # num_str is now a string '123.45'

Example: num_bool = True; num_int = int(num_bool); # num_int is now an integer 1

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?