• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 4 fuera de 37 páginas
Examen

D522 Python Syntax Question with Verified Correct Answers

Document preview thumbnail
Vista previa 4 fuera de 37 páginas

D522 Python Syntax Question with Verified Correct Answers

Vista previa del contenido

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)

Información del documento

Subido en
15 de septiembre de 2026
Número de páginas
37
Escrito en
2026/2027
Tipo
Examen
Contiene
Preguntas y respuestas
$15.99

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
KenAli
2.6
(18)
Vendido
125
Seguidores
5
Artículos
26522
Última venta
1 día hace



Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes