• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 4 out of 37 pages
Exam (elaborations)

D522 Python Syntax Question with Verified Correct Answers

Document preview thumbnail
Preview 4 out of 37 pages

D522 Python Syntax Question with Verified Correct Answers

Content preview

D522 Python Syntax Question with Verified
Correct Answers
Assigning multiple variables in a single line

x, y, z = "router", "switch", "firewall"



print(x) print(y) print(z)

Assigning same value to multiple variables in a single line

switch1 = switch2 = switch3 = "Juniper"

Unpacking collections

extracting elements from iterable objects like lists or tuples and assigning them to individual

variables. It simplifies code by enabling simultaneous assignment of values, enhancing

readability and conciseness in assignments and function returns.



ip_addresses = ["172.20.200.10", "172.20.200.11", "172.20.200.12"]



ip1, ip2, ip3 = ip_addresses



print(ip1) print(ip2) print(ip3)

The existing list "device_information" contains a device name, IP address, and subnet

mask, respectively. Assign each value of "device_information" to its own variable using

a single line of code by unpacking. The new variable names should match the existing

print statements.

,device_information = ["name", "ip_address", "subnet_mask"

"laptop1",

"10.0.0.1",

"255.255.255.0"

]

# create variables from device_information



name = "laptop1"

ip_address = "10.0.0.1"

subnet_mask = "255.255.255.0"



# do not edit below this line



print(f"Device Name: {name}")



print(f"IP Address: {ip_address}")



print(f"Subnet Mask: {subnet_mask}")

output print to console with different variable types

x = 15 y = "server"



print(x, y)



- separate the variables with a comma

,local variable

A variable defined inside a function. A local variable can only be used inside its function.

Parameters of a function are also a special kind of local variable.



def my_function():

x = "I am local"

print(x)

my_function()

print(x) <-- This would cause an error!

global variable

x = "I am global"

def my_function():

print(x)



# The function can see it




my_function()

print(x)



# The rest of the code can see it too

new function w/no parameters

# the function will do the same thing every time (with no parameters)

, #syntax

def name():



#example syntax

def say_hi():

print("Hi!")

new function w/parameters

def name(parameters):

#The function needs specific info to do its job.

#example syntax

def say_hi(name):

print("Hi " + name)

return function

return does not output anything to the console, it give a value to the computer/code.

What happens after return? The function stops immediately. Anything written below the

return line inside that function is ignored.

Do I need a variable? Only if you want to save that "answer" to use later.

def add(a, b):

return a + b # Send the sum back

# The line below is like saying: total = 5 + 10

total = add(5, 10)

Document information

Uploaded on
September 15, 2026
Number of pages
37
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$15.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
KenAli
2.6
(18)
Sold
125
Followers
5
Items
26522
Last sold
1 day ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions