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
Twitter
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 method. de
Python Exercise 7 --- "Snake, Water, Gun" Today's task for you guys will be to develop your first-ever Python game i.e., "Snake Water Gun." (Just like --- Rock, Paper, Scissor) Most of you must already be familiar with the game. Still, I will provide you with a brief description. This is a two-player game where each player chooses one object. As we know, there are three objects, snake, water, and gun. So, the result will be Snake vs. Water: Snake drinks the water hence wins. Water vs. Gun: The gun will drown in water, hence a point for water Gun vs. Snake: Gun will kill the snake and win. In situations where both players choose the same object, the result will be a draw. Now moving on to instructions: You have to use a random choice function that we studied in tutorial #38, to select between, snake, water, and gun. You do not have to use a print statement in case of the above function. Then you have to give input from your side. After getting ten consecutive
Python Tutorial 24 --- "Using Python External & Built In Modules" DOC: In Python, a module can be defined as a file containing a runnable python code. The extension used by modules in Python is .py. Hence any simple file containing Python code can be considered a module if its extension is .py. The file and module names are the same; hence we can call a module only by name without using the extension. Along with this, a module can define functions, classes, and variables. There are two types of modules. Built-in External Built-in Modules: Built-in modules are already installed in Python by default. We can import a module in Python by using the import statement along with the specific module name. We can also access the built-in module files and can read the Python code present in them. Newly integrated modules are added in Python witch each update. Some important modules names are as follows Modules Names Purpose calendar used in case we are working with
Comments
Post a Comment