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

Beautify third-party API with Kotlin

Box Bot — Unity Tutorial 4

The rise of the new enterprise: The way forward in the new normal

The Rise of the new enterprise in the new normal

Get To Know Your”self”… but it’s not about you…

The Second Year of a Computer Science Degree at Northeastern University

A quick introduction to some refactoring techniques

What you have to know before creating a container of a redis docker image

What is this Thing?

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

Iterables vs Iterators in Python

Testing software — a practical guide to write tests for machine learning pipelines

10 Tips and Tricks for Writing Clean Python Code

Callables and functions in Python: a simple explanation with an example