#๐Ÿ”’ python beginner's question

53 messages ยท Page 1 of 1 (latest)

devout boltBOT
#

@dull axle

Python help channel opened

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.

frosty bobcat
#

they have a special meaning. init is the initializer to initialze the object

reef maple
#

You can think of classes as a way to group data. Classes allows you to store variables and functions in a closed scope.

Dunder methods are special methods for classes which define some lower level methods, one of them is the __init__ also called the constructor method. This always gets fired once during instantiation of a class

class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

person1 = Person("baegy", 28)
# The Person("baegy", 28) is called the instantiation of the Person class. And now the variable person1 holds the created instance.

From the above example you can now access those variables from the instantiated class and also you can create endless number of instances of a Person class

print(person1.name, person1.age)

person2 = Person("Jiggly", 18)
print(person2.name, person2.age)
#

__init__ is usually used to create instance variables of the class

dull axle
#

oh oof wrong reply

dull axle
reef maple
#

Wym

dull axle
#

like

#

uhm

#

the line above

#

oh wait nvm I am dumb

reef maple
#

Lmao

#

It's alr

#

Lmk if you understand

frosty bobcat
#

so it goes line by line

dull axle
#

I see

frosty bobcat
#

everything which is under the current line does not exists (yet)

dull axle
#

and uhm

#

this might be another quite dumb question

#

but for the variable person1, can it also be written as either {} or [] instead of tuples?? why or why not?

reef maple
#

You can ask you don't need to feel dumb about it

dull axle
dull axle
#

either person1 = Person["baegy", 28] or person1 = Person{"baegy", 28}

reef maple
#

Yeah that's not a valid syntax

dull axle
#

why?

frosty bobcat
#

something like Uniform Initialization does not exists

reef maple
#

{} is a used to define a set or a dictionary, [] is used to define a list or index through a list / tuple or dictionary depending on how it's used, () is used to create a tuple or call a function (depending on how it's used again)

frosty bobcat
#

you get an new instance when you call the class object and calling in Python is always ()

dull axle
#

ohh

reef maple
eternal schooner
#

!e

x = 1, 2, 3
print(type(x))
devout boltBOT
dull axle
frosty bobcat
#

#roles

#

there you can assign the role to you

#

archived channels access

dull axle
#

oh

reef maple
#

Get the archived channel access

dull axle
#

ok

reef maple
#

!e

x = (1) # doesn't create a tuple
print(type(x))

y = (1,) # or y = 1,
# creates a tuple
print(type(y))
devout boltBOT
dull axle
#

Damn. thank you guys for the input my good sir ๐Ÿท. may the rest of your day and ones to follow, be in your favour

devout boltBOT
#
Python help channel closed

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.

#

๐Ÿ”’ python beginner's question