#๐ want to get value of variables outside the functions to inside the function without the use of cla
49 messages ยท Page 1 of 1 (latest)
@bronze wasp
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
see python inhertance
wdym
thats the techinal term in software engineering, "inhertance"
is that not to do with classes though
works for everything tbh
functions raw variables
you declar A = y at the top of your code everything below inherts that
you return A from a function it goes backup to A
there is also the "global" varibles
i tried global variables but i couldnt get it to work
i put global limit and global cardavlue at the start of the function
a = 5
def cards(a):
### do a thing
return a
print(a) # a will be whatever it is in "do a thing"```
inhertance, constructors, instansation and polymorphism are all generic sofware engineering terms/concpets, once you master them you can find anythin in any lang you wanna do
๐
https://www.w3schools.com/python/python_classes.asp good guide for some generic terms after that
ok thanks i will read through it
are you more a visual audio learner?
Object Oriented Programming is an important concept in software development. In this complete tutorial, you will learn all about OOP and how to implement it using Python.
๐ป Code: https://github.com/jimdevops19/PythonOOP
๐ Tutorial referenced for a deeper explanation about repr: https://www.youtube.com/watch?v=FIaPZXaePhw
โ๏ธ Course develo...
i will have a look at both because im really terrible at classes and stiff right now
thanks for the help
It'll click.
no... inheritance is strictly an OOP concept. Where variables are available is called scope.
inheritance has to do with modelling relationships between types of objects
a cow is an animal, for example
class Animal:
pass
class Cat(Animal):
pass
class Cow(Animal):
pass```
!e ```py
class Alpha:
def a(self):
print('alpha')
class Beta(Alpha):
def b(self):
print('beta')
alpha = Alpha()
beta = Beta()
beta.a()
beta.b()
alpha.a()
alpha.b()```
:x: Your 3.12 eval job has completed with return code 1.
001 | alpha
002 | beta
003 | alpha
004 | Traceback (most recent call last):
005 | File "/home/main.py", line 14, in <module>
006 | alpha.b()
007 | ^^^^^^^
008 | AttributeError: 'Alpha' object has no attribute 'b'
Instances of Beta are everything that instances of Alpha are except where otherwise defined in Beta.
A cow is everything an animal is, plus the differences that make it a cow.
Inheritance is probably not especially relevant to your project.
this looks super wrong. i know i'm new, but shouldnt this not do anything to a outside the function unless you "a = cards(a)" before you "print(a)"?
yeah, actually. i can feel my brain expanding!
welcome to programming ๐
i mixed the two ways of doing the thing up and half-failed both!
i mean i broke out juypiter to test it
Scope/LEGB.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.