1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Yuki888 [10]
3 years ago
13

Can somoene explain the function of-def __init__():In python programming language​

Computers and Technology
1 answer:
JulsSmile [24]3 years ago
8 0

Answer:

def is a keyword used to define a function, placed before a function name provided by the user to create a user-defined function

__init__ is one of the reserved methods in Python. In object oriented programming, it is known as a constructor. Python will call the __init__() method automatically when you create a new object of a class, you can use the __init__() method to initialize the object’s attributes.

Example code:

class Person:

 def __init__(self, name, age):

   self.name = name

   self.age = age

p1 = Person("John", 36)

print(p1.name)

print(p1.age)

Summary

  • Use the __init__() method to initialize the instance attributes of an object.
  • The __init__() doesn’t create an object but is automatically called after the object is created.
You might be interested in
1| def saveUserProfile(firstName, lastName, age, height, country):
Feliz [49]

Answer:

Joyner

David

USA

1.8

30

Explanation:

def saveUserProfile(firstName, lastName, age, height, country):

This is the definition of function named saveUserProfile which accepts the following parameters:

  • firstName
  • lastName
  • age
  • height
  • country

filename = lastName + firstName + ".txt"

When the file is created it will be named as the lastName and firstName string combined with .txt as extension. For example if the lastName contains the name string Joyner and firstName contains the name David then the file created to be written is named as JoynerDavid.txt

outputFile = open(filename, "w")

This statement uses open() method in write mode and uses outputFile object to access the file. "w" represents write mode i.e. file is opened in write mode to write on it.

a) Joyner is written on line 1 of that file because of the following statement of above function:

print(lastName, file = outputFile)

This statement prints the string stored in lastName i.e. Joyner. Here outputFile opens the file in "w" write mode and writes the last name to the first line of the file.

b) David is written on line 2 of that file because of the following statement of above function:

print(firstName, file = outputFile)

This statement prints the string stored in firstName i.e. David. Here outputFile opens the file in "w" write mode and writes the first name to the second line of the file.

c) USA is written on line 3 of that file because of the following statement of above function:

print(country, file = outputFile)

This statement prints the data stored in country i.e. USA. Here outputFile opens the file in "w" write mode and writes the country name to the third line of the file.  

d) 1.8 is written on line 4 of that file because of the following statement of above function:

print(height, file = outputFile)

This statement prints the value stored in height i.e. 1.8. Here outputFile opens the file in "w" write mode and writes the height value to the fourth line of the file.  

e) 30 is written on line 5 of that file because of the following statement of above function:

print(age, file = outputFile)

This statement prints the value stored in age parameter of function saveUserProfile i.e. 30. Here outputFile opens the file in "w" write mode and writes the age value to the fifth line of the file.  

7 0
3 years ago
Have you ever tried using such a camera?​
guapka [62]

Answer: yeah i mean i use my canon camera

Explanation:

7 0
2 years ago
Piecewise functions are sometimes useful when the relationship between a dependent and an independent variable cannot be adequat
Andru [333]

Answer:

//Set a piecewise function v(t).

function v = vpiece(t)

//Set the condition first for t.

if ((0<=t)and(t<=8))  //Set if condition

// first equation of velocity.

   v = 10*t^2 - 5*t;

//Set the condition second for t.

elseif((8<=t)and(t<=16))  //Set elseif condition

//second equation of velocity.

v = 624 - 5*t;

//set the condition third for t.

elseif((16<=t)and (t<=26))  //Set elseif condition  

//third equation of velocity.

v = 36*t + 12*(t - 16)^2;

//Set the fourth condition for t.

elseif t>26

//fourth equation of velocity.

v = 2136*exp(-0.1*(t-26));

//Last condition.

else

//fifth equation of velocity.

v = 0;

//End of the function v.

end

//set a variable and initialize it to 0.

a=0;

//Starting the loop.

for j = -5: 0.5 : 70

//Increment the value of a by 1.

a = a + 1;

t(a) = j;

v(a) = vpiece(t(a));

//End of for loop.

end

//Plot the graph between t and v.

plot(t,v)

//Write the label for the x-axis.

xlabel('t')

//Write the label for the y-axis.

ylabel('velocity')

//Write the title of the plot.

title('Plot of velocity vs t')

Explanation:

Firstly, we set the piecewise method.

Then we set the first condition, after that we apply the condition of velocity.

Then we set the second condition, after that we apply the condition of velocity.

Then we set the third condition, after that we apply the condition of velocity.

Then we set the fourth condition, after that we apply the condition of velocity.

Then we set the last or fifth condition, after that we apply the condition of velocity.

Then we set the variable "a" to 0.

Then start the loop and increase the value by 1.

And after all, we write the title of the plot.

8 0
3 years ago
A stored program computer is designed to compute precisely one computation, such as a square root, or the trajectory of a missil
mr Goodwill [35]

Answer: False

Explanation:

 The given statement is false as, a stored program computer is one of the type of computer system which storing the program instruction in the form of electronic memory.

  • It perform different types of tasks in the sequence and it also enables the digital computer system more effective and flexible.
  • In this stored program computer the program instructions are get stored on the plugboards.

Therefore, the given statement is false.

4 0
3 years ago
This is the recorded history of the development of a group functioning within an organization. Identify the sentence that refers
Vikentia [17]
This is the recorded history of the development of a group functioning within an organization. Identify the sentence that refers to the norming stage of group development.

. The group then created a working structure that everyone agreed with.

5 0
3 years ago
Read 2 more answers
Other questions:
  • George and Miguel want to know more about their local and online competitors and about the retail industry. What is the best way
    9·1 answer
  • "A user reports that the corporate web server cannot be accessed. A technician verifies that the web server can be accessed by i
    8·1 answer
  • Which value can be entered to cause the following code segment to display the message: "That number is acceptable." int number;
    11·1 answer
  • How should a Salesforce Admin fulfill those requirements? Universal Containers launches a Partner Community for their resellers
    13·1 answer
  • JAVA QUESTION::
    10·1 answer
  • What is the first step a user should take toward generating an index?
    7·1 answer
  • Plz answer this....quickkkkk​
    7·2 answers
  • Ano ang humahati ng globo ng equdor
    8·1 answer
  • Can someone help me with this lab assignment? I really do not know what should I do?
    5·1 answer
  • Who is your favorite person from squid game?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!