This page contains examples of basic concepts of Python programming; List Programs; String Programs; Dictionary Programs. Tuple Programs; Searching and Sorting Programs; Pattern Printing; Date-Time Programs; More Python ...
About Me
Get link
Facebook
X
Pinterest
Email
Other Apps
I write daily BLOGS about PYTHON with "Source Code"
Python Tutorial 38 --- "Self & __init__() (Constructors)(OOPS 3)" Doc --- In this tutorial, we will be discussing methods and constructors in detail. If you are familiar with any other object-oriented programming language, then the concept will be easy for you to grasp. So, let us begin with the Method. Method: A method is just like a function, with a def keyword and a single parameter in which the name of the object has to be passed. The purpose of the method is to show all the details related to the object in a single go. We choose variables that we want the method to take but do not have to pass all of them as parameters. Instead, we have to set the parameters we want to include in the method during its creation. Using methods make the process simpler and a lot faster. Self keyword: The self keyword is used in the method to refer to the instance of the current class we are using. The self keyword is passed as a parameter explicitly every time we define a m...
Python Exercise 4: "Number Guessing Game" Q: You have to build a "Number Guessing Game," in which a winning number is set to some integer value. The Program should take input from the user, and if the entered number is less than the winning number, a message should display that the number is smaller and vice versa. Instructions: 1. You are free to use anything we've studied till now. 2. The number of guesses should be limited, i.e (5 or 9). 3. Print the number of guesses left. 4. Print the number of guesses he took to win the game. 5. “Game Over” message should display if the number of guesses becomes equal to 0. You are advised to participate in solving this problem. This task helps you become a good problem solver and helps you accept the challenge and acquire new skills. Solution: print ( "Hii! Welcome, \n " , "This a number guessing game, " "made by Saswata \n " , "Let's Start \n " ) n...
Python Tutorial 13 --- "Short Hand If Else Notation In Python" This PROGRAM or TUTORIAL about Python's "Short Hand If Else Notation In Python" DOC Before going through the if-else short-hand statement, we must be familiar with the basic definition, so we know what the short-hand statement actually is. In basic English, shorthand can be said as “a basic way of writing using abbreviations or symbols”. For example, we do not use the full name, Kentucky Fried Chicken, instead we use its abbreviation that is KFC. Writing in such a compact manner is known as shorthand. Now let us move towards the definition of shorthand with respect to the Python language. “An executable statement, written in so compact manner that it comprises of only a single line of code is known as shorthand statement.” Python supports many sorts of shorthand statements and with the help of these statements, we can write our code in a more compact sort or form using less space. We learned the or...
Comments
Post a Comment