Learning Python - Pointers

  Рет қаралды 18,909

Code Militia

Code Militia

3 жыл бұрын

Python Pointers; or lack there of
If you liked this video Subscribe for more like it!
Support me on Patreon! / learndevops
Donate to me directly, my paypal username is slimg00dy
www.paypal.com/cgi-bin/webscr...
License:Creative Commons Attribution 3.0kzbin.info?even...

Пікірлер: 29
@thatlazyburger9855
@thatlazyburger9855 3 жыл бұрын
Thanks a lot. I have a test tomorrow and this is gonna help big time. Ty
@Alireza13488
@Alireza13488 2 жыл бұрын
Very good video, but It is also worth mentioning, pointers do exist for arrays or any other mutable object in python
@Code-Militia
@Code-Militia 2 ай бұрын
Thank you for the update! Will correct myself in a future video.
@user-wk6mb7mw3g
@user-wk6mb7mw3g 7 ай бұрын
Python does have pointers. Try your simple demonstration on "lists".
@frodobaggins3974
@frodobaggins3974 3 жыл бұрын
Hehe, try this: a = [1, 2, 3] b = a a.append(4) print(b) Surprised? :)
@Code-Militia
@Code-Militia 3 жыл бұрын
I will try this out and figure out why the result is the result. Thank you so much!
@predator1011X
@predator1011X 3 жыл бұрын
@@Code-Militia i would like to know this too
@frodobaggins3974
@frodobaggins3974 3 жыл бұрын
@@predator1011X Short answer: memory management. Lists are mutable objects, once you create a list, and make a link between the variable name (also an object in Python!) and the list object, the link holds even if you change the content of the linked object (a list in this case). Same goes for sets, dicts and user-created classes. It's rooted in the 'everything is an object' ideology. So if you want to mimic a pointer behaviour in Python, contain the variable value in a list. Saying this, in C++ we use pointers for speed and for smarter memory management. In Python you will not see any of these benefits, as the list is stored as an object anyway, not a simple addressed heap value. But yeah, it's there, and it works - if you need it.
@ranitchatterjee5552
@ranitchatterjee5552 2 жыл бұрын
No, xD!!
@exoticme4760
@exoticme4760 Жыл бұрын
PIN THIS
@basictech9069
@basictech9069 2 жыл бұрын
made a 5 min video to tell python dosent have pointers?? seriously???
@arjunmehta2853
@arjunmehta2853 Жыл бұрын
It's for people who don't even know what pointers are.
@mykhailoshpakov6487
@mykhailoshpakov6487 3 жыл бұрын
As I got, when you assign 5 to x , you assign to x a memory location , where instance of int class is stored. Then, since int is unchangeable type of data, once you assign 9 to x , you create another instance of int class which is stored at another location. Variable y points to precedent memory location, where 5 is stored. Could you answer me, is there any practical way to pass inside a function a variable , change it inside the function so that global variable changes also ?
@Code-Militia
@Code-Militia 3 жыл бұрын
Good question, yes there is a way to change a global function from a local variable by using the global keyword. Although, in my experience, I’ve never had to change the global variable from a local function. I’ve used global lists and dictionaries and always added keys and items to the list. Don’t need to use the global keyword then. thispointer.com/python-how-to-use-global-variables-in-a-function/
@mykhailoshpakov6487
@mykhailoshpakov6487 3 жыл бұрын
@@Code-Militia Ok. Have a Nice day !
@Code-Militia
@Code-Militia 3 жыл бұрын
You too. Hope I was able to help.
@casualgamingz153
@casualgamingz153 Ай бұрын
Try on lists lil bro
@mykhailoshpakov6487
@mykhailoshpakov6487 3 жыл бұрын
Thank you for tutorial
@Code-Militia
@Code-Militia 3 жыл бұрын
You're welcome 😊
@drac8854
@drac8854 3 жыл бұрын
Is there a way to get value from id For example lets say i do x=10 y=id(x) Now how can i print value of y because now if i print value of y it will be an integer which is memory I want to print whats at that memory Like address(&) in c
@Code-Militia
@Code-Militia 2 жыл бұрын
While you can loop through globals().values() to get the ID and return the value, it's not best practice because there are too many variables to go through and your app could be slowed down by a lot. >>> x = 10 >>> xAddress = id(x) >>> [y for y in globals().values() if id(y)==xAddress] [10, 10] >>>
@frodobaggins3974
@frodobaggins3974 2 жыл бұрын
Without checking first whether this particular ID exists? No and there are good reasons for not doing it. If Python interpreter tried to access memory address that was not allocated to it in the first place (which is likely the case), it would have caused a segmentation fault and the interpreter would be unconditionally killed by the operating system (SIGSEGV). Programs cannot read memory that has not been allocated to them... If you're interested in further explanation read about dereferencing null pointers in C - as this is what you somewhat try to achieve.
@raayaansahu2525
@raayaansahu2525 3 жыл бұрын
ahaha lovely kinda hilarious though
@Code-Militia
@Code-Militia 3 жыл бұрын
Finally, someone finds it funny 😄
@Mogwai88
@Mogwai88 3 жыл бұрын
What color scheme are you using here?
@Code-Militia
@Code-Militia 3 жыл бұрын
I use fish shell with sushi color scheme, this particular set of colors is from VSCode shell with bpython running, and that’s not a typo.
@shambhav9534
@shambhav9534 3 жыл бұрын
So, you just trolled me? I wanted to use pointers in python, I knew it wasn't possible, then I saw the title, got so happy, then... all went down... And btw C has pointers, that's stupid of you to be uncertain, C++ is just C but more OOP and with modern syntax, and more tools, only more tools, not like C++ has any more features.
@Code-Militia
@Code-Militia 3 жыл бұрын
You’re right, that was an unprofessional jerk move by me. I’ll put a troll tag
@amritlohia8240
@amritlohia8240 Жыл бұрын
Actually it *is* possible, through the ctypes module. See e.g. here: kzbin.info/www/bejne/opTPc2WPZ5ehl9E.
Learning Python - Lists & Dicts
45:47
Code Militia
Рет қаралды 199
Python's 5 Worst Features
19:44
Indently
Рет қаралды 75 М.
¡Puaj! No comas piruleta sucia, usa un gadget 😱 #herramienta
00:30
JOON Spanish
Рет қаралды 22 МЛН
Joven bailarín noquea a ladrón de un golpe #nmas #shorts
00:17
I PEELED OFF THE CARDBOARD WATERMELON!#asmr
00:56
HAYATAKU はやたく
Рет қаралды 37 МЛН
Python Decorators in 15 Minutes
15:14
Kite
Рет қаралды 420 М.
Functions vs Classes: When to Use Which and Why?
10:49
ArjanCodes
Рет қаралды 137 М.
you will never ask about pointers again after watching this video
8:03
Low Level Learning
Рет қаралды 2 МЛН
5 Tips To Write Better Python Functions
15:59
Indently
Рет қаралды 77 М.
Introducing Pointers in Python using the Ctypes Library
17:02
CodersLegacy
Рет қаралды 6 М.
How to Use the Two Pointer Technique
10:56
Team AlgoDaily
Рет қаралды 83 М.
Python 101: Learn the 5 Must-Know Concepts
20:00
Tech With Tim
Рет қаралды 1 МЛН
3 Bad Python Habits To Avoid
10:40
Indently
Рет қаралды 45 М.
Уроки Python с нуля / #12 - Функции (def, lambda)
22:21
Школа itProger / Программирование
Рет қаралды 203 М.
Carregando telefone com carregador cortado
1:01
Andcarli
Рет қаралды 1,5 МЛН
Приехала Большая Коробка от Anker! А Внутри...
20:09
РасПаковка ДваПаковка
Рет қаралды 82 М.
Добавления ключа в домофон ДомРу
0:18
3D printed Nintendo Switch Game Carousel
0:14
Bambu Lab
Рет қаралды 4,3 МЛН
Wow AirPods
0:17
ARGEN
Рет қаралды 1,1 МЛН