Ads skipped

Python 101: Learn the 5 Must-Know Concepts

1.6M views · May 20, 2023 · Education

Comments · 766

  • @TechWithTim · 3 years ago (edited) · pinned

    Start your career in Software Development and make $80k+ per year! <a href="https://coursecareers.com/a/techwithtim?course=software-dev-fundamentals">https://coursecareers.com/a/techwithtim?course=software-dev-fundamentals</a>

    49

  • @AFuller2020 · 3 years ago

    It&apos;s starts at <a href="https://www.youtube.com/watch?v=mMv6OSuitWw&amp;t=105">1:45</a>, if you&apos;re in a hurry.

    27

  • @nigh_anxiety · 3 years ago

    At <a href="https://www.youtube.com/watch?v=mMv6OSuitWw&amp;t=210">3:30</a>, your description of why changing x does not change y is incorrect and seemingly makes the same mistake many new Python developers make when working with mutable objects such as lists. <br>The assignment `y = x` does NOT create a copy of the original tuple in y. &nbsp;y and x both point to the exact same tuple object in memory. &nbsp;This can be shown with either `y is x` (outputs true) or by printing `id(x)` and `id(y)` which will be identical. &nbsp; <br> &nbsp;When you subsequently assign x to a new tuple, x now points at a new tuple object at different location in memory, which you can see by checking id(x) before and after that assignment.<br> &nbsp; All variables in Python are references to objects. &nbsp;Doing an operation like `y = x`, for any type of object in x, simply makes y a reference to the same object, which is why mutable objects passed as arguments to a function can be mutated by that function. &nbsp;Likewise, anytime you assign a new value &nbsp;to a variable referencing an immutable object, you get a brand new object. &nbsp; if a = 1000, and then a += 1, you also change the id of a to a brand new object of &lt;class &apos;int&apos;&gt;<br> &nbsp; For some more interesting examples, if you do something like `for i in range(-1000, 1001, 50): print(i, id(i))`, you&apos;ll see the id value change for each value, but in most implementations it alternate back and forth between a couple of ids as the interpreter reuses the memory block that was just freed by the garbage collector from the value in the previous loop. &nbsp;The exception is for ints in the range of -5 to 255 (at least in CPython) you&apos;ll get a different set of ids because those int objects are pre-allocated when interpreter starts and remain in memory to improve performance, as do the None object and True/False.

    12

  • @PaulM-c8h · 3 years ago

    My cat&apos;s breath smell like cat food.

    43

  • @apmcd47 · 3 years ago (edited)

    At around the 4 minute mark you are confusing immutability with references. When you do &apos;y = x&apos; what you are doing is assigning the reference of the object that x is pointing to, to y. When you assign a new object to x it drops the old reference and now refers to a new object, meanwhile y still refers to the original object. You use tuples in this example, but this is true for lists and dicts. When you change to lists, all you are really demonstrating is that x and y refer to the same object.<br><br>With your get_largest_numbers() example, if you were to pass a tuple into the function you would get an AttributeError because you were passing an immutable object which doesn&apos;t have the sort method.

    201

  • @firefly7076 · 3 years ago

    about <a href="https://www.youtube.com/watch?v=mMv6OSuitWw&amp;t=244">4:04</a> your explanation of changing values in mutable v. immutable types is really weird. &nbsp;You eventually get to saying that variables are actually just pointers to objects, and saying x=y is just reassigning the pointers to be the same (in other words, there is an object that y points towards, and executing x=y is setting the pointers to be the same) but you also say that immutable types do a clone instead which is... wrong. &nbsp;Here&apos;s some code that can be used to see that:<br><br>x = (1, 2) <br>y = x <br>print(y is x)<br><br>output:<br>&gt; True<br><br>the two numbers should be the same, but should be different each time you run.<br>The &apos;y is x&apos; statement is comparing the ids of the numbers, aka where they are in the code. &nbsp;They&apos;re the same object.<br>Some more code to show that &apos;is&apos; is not just a fancy &apos;==&apos;:<br><br>x = (1, 2) <br>y = tuple([1, 2])<br>print(y is x, y == x)<br><br>ouput:<br>&gt; False, True<br><br>Different objects.

    6

  • @jeyhey5320 · 3 years ago

    I think what you call „mutable“ and „immutable types“ are better described as „types passed by reference“ and „types passed by value“. Mutability is another concept that is not directly related to this.

    7

  • @narutoxboruto873 · 3 years ago (edited)

    There is an error in the time stamps ,names of &nbsp;function arguments and if __ are interchanged

    35

  • @Gaurav-gc2pm · 3 years ago

    Working as a python dev and in my 1 year of practicing python... no one ever explained this well... you&apos;re a GEM TIM

    160

  • @yankluf · 2 years ago

    Fiiiiinally I understand those &nbsp;*args/**kwargs!!! Thank youuuuuuu!! 🎉🎉

    3

  • @crashandfreeze · 1 year ago

    being a C programmer, this immutable/mutable thing is hard to get used to. In C, it&apos;s explicit. In Python, it&apos;s implicit in the type of the object. Which you have to remember.

    3

  • @zecuse · 3 years ago (edited)

    Some details skipped about *args and **kwargs:<br>A forward slash &quot;/&quot; can be used to force parameters to be positional only, thereby making them required when calling and not by name. So, def function(a, b, /, c, d, *args, e, f = False, **kwargs) means a and b cannot have default values, are required to be passed when calling function, AND can&apos;t be supplied with their parameter names. e must also be supplied with a value when called.<br><br>Naming the first * is not required. Doing so simply allows the function to take an arbitrary amount of positional parameters. def function(a, b, /, c, d, *, e, f = False) would require at least 5 arguments (no more than 6) passed to it: a and b are required, c and d are also required and optionally passed as keywords, e must be passed as keyword, f is completely optional, and nothing else is allowed.<br><br>/ must always come before *. * must always come before **kwargs. **kwargs must always be last if used.

    91

Up next

LIVE

Learn Python With 5 Projects - From Beginner to Advanced

Tech With Tim · 205K views

LIVE

Python As Fast as Possible - Learn Python in ~75 Minutes

Tech With Tim · 2.2M views

LIVE

Artificial Intelligence & Machine Learning Explained | 1 Hour Technical Seminar | CSE

Jnnce Math Sphere · 32 views

LIVE

Learn Pandas in 30 Minutes - Python Pandas Tutorial

Tech With Tim · 404K views

LIVE

System Design Explained: APIs, Databases, Caching, CDNs, Load Balancing & Production Infra

Hayk Simonyan · 777K views

LIVE

Unsafe Rust Explained by Building a Database Engine 🦀 Part 1: Raw Pointers, Memory & Miri

AI Edge Flow · 210 views

LIVE

Python Full Course for Beginners

Programming with Mosh · 8.2M views

LIVE

PLEASE Learn These 10 Advanced Python Features

Tech With Tim · 178K views

LIVE

MATLAB Crash Course for Beginners

freeCodeCamp.org · 1.7M views

LIVE

I finally saw quantum physics with my own eyes... (It's spookier than I expected)

Veritasium · 21M views

LIVE

Object Oriented Programming (OOP) in Python

Traversy Media · 296K views

LIVE

Python Machine Learning Tutorial (Data Science)

Programming with Mosh · 3.7M views

LIVE

Python Full Course for Beginners | Complete All-in-One Tutorial | 9 Hours

Dave Gray · 1.1M views

LIVE

Building AI Agents in Pure Python - Beginner Course

Tech With Tim · 269K views

LIVE

Asyncio in Python - Full Tutorial

Tech With Tim · 403K views

LIVE

Lecture 1: Introduction to CS and Programming Using Python

MIT OpenCourseWare · 2.5M views

LIVE

Certified entry Level Python programmer course - Python Institute

Science Course · 37K views

LIVE

👩‍💻 Python for Beginners Tutorial

Kevin Stratvert · 4.6M views

LIVE

Python for Beginners - Learn Coding with Python in 1 Hour

Programming with Mosh · 26M views

LIVE

Python Object Oriented Programming (OOP) - For Beginners

Tech With Tim · 4M views

YouTube, with the door locked.

Aegis plays a clean stream instead of YouTube's player, so pre-roll ads, trackers, and fingerprinting never ride along. Drop Shields any time if you want the official player back.