Python under the hood — tips and tricks from a C++-programmers’ perspective 03

# list -the same for sets (use {} ) and tuples (use () )a = [1, 2, 3]
b = [3, 4, 5]
c = [*a, *b]
print("a = ", a) # [1, 2, 3]
print("b = ", b) # [3, 4, 5]
print("c = ", c) # [1, 2, 3, 3, 4, 5]
# non-keyword argumentst = (1, 2, 3)def tt(*args):for arg in args:
print(arg+1)
tt(*t) # 2, 3, 4
###### keyword argumentsd = {'a' : 1, 'b' : 2}def dd(**kwargs):
for key, value in kwargs.items():
print("Key: ", key, " value: ", value)
dd(**d) # Prints: Key: a value: 1# Key: b value: 2
r = 5 if True else 4 # 5
l = list(range(10))
l_even = [x for x in l if x%2 == 0]
s_even_sq = {x**2 for x in l if x%2 == 0}
print("l = ", l) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
print("l_even = ", l_even) # [0, 2, 4, 6, 8]
print("s_even_sq = ", s_even_sq) # {0, 64, 4, 36, 16}
a = 1
b = 1
c = a
print("a == b :", a == b) # True
print("a == c :", a == c) # True
print("a is b :", a is b) # True
print("a is c :", a is c) # True
######x = [1, 2, 3, 4, 5]
y = [1, 2, 3, 4, 5]
z = x
print("x == y :", x == y) # True
print("x == z :", x == z) # True
print("x is y :", x is y, "<--") # False
print("x is z :", x is z) # True

--

--

--

Deep Learning and AI solutions from Budapest University of Technology and Economics. http://smartlab.tmit.bme.hu/

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Swift method dispatch

Flash Stock Firmware on Samsung Galaxy J2 SM-J200GU

Flash Stock Rom on Samsung Galaxy

Glow — Local MQTT

Achieving Data Agility With The Combined Strengths of AWS and Confluent

Qiskit Camp 101

Ansible With AWS

Is it easy to test a Flutter widget?

How To Navigate The Linux Filesystem?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
SmartLab AI

SmartLab AI

Deep Learning and AI solutions from Budapest University of Technology and Economics. http://smartlab.tmit.bme.hu/

More from Medium

3 Methods for Handling Missing Values with Python

SciPy-Tutorial

Two Ways to Immediately Improve Your Python Code

Python message

Tuple in Python : Creating, Accessing Tuple