What is function in python:
*In Python, a function is a reusable block of code that performs a specific task, allowing you to organize and modularize your code.
*Functions in Python. You use functions in programming to bundle a set of instructions that you want to use repeatedly or that, because of their complexity, are better self-contained in a sub-program and called when needed. That means that a function is a piece of code written to carry out a specified task
TYPES OF FUNCTION:
The are two types of function:
*built in function
*user define function
BUILT IN FUNCTION:
Predefined functions provided by Python, like print(), len(), etc.
USER DEFINE FUNCTION:
Functions that you create yourself to perform specific tasks.
DEFINE A FUNCTION:
A function is defined as a relation between a set of inputs having one output each. In simple words, a function is a relationship between inputs where each input is related to exactly one output. Every function has a domain and codomain or range. A function is generally denoted by f(x) where x is the input.
WHAT IS VARIABLE IN PYTHON:
*In Python, a variable is a named memory location that stores a value. Variables are used to store information that will be used during the program.
*Python variables are simply containers for storing data values. Unlike other languages, such as Java, Python has no command for declaring a variable, so you create one the moment you first assign a value to it. Python variables are simply containers for storing data values.
HOW TO CREATE A VARIABLE:
*To create a variable, use the assignment equal sign (=)
*Put the variable's name on the left and the value it should store on the right
*For example, x = 42
Types of variables:
1) Local variables: Defined inside a function and can only be accessed within that function
2) Global variables: Defined outside of any function and can be accessed from anywhere in the code
3) Booleans: Have two possible values: True and False
4) Tuples: Store multiple items in a single variable
5) Strings: Sequences of characters, and you can think of them as words or sentences
6) Integers: Whole numbers, negative, positive or zero
--------------------x-------------------
portable
*object oriented programming
*multi paradigm language
*procedural oriented-c
*modular programming-module
WHAT IS FUNCTION:
(Set of instruction with a name)
attending_class:
1.dress
2.walking
3.entering
4.sitting
5.listening
6.taking notes.
ride_bike()
input()
Naming convention for functions:
1.function name should be meaningful
sit,stand,abcd,pqrs.
2.function should not be nonu,should be verb.
3.should end with()
name=input()
print ("welcome to python",name)
~ -->tilde
`` ->back ticks.
pwd --> print working directory
folder --> directory
Terminal
----> pwd
----> ls
ls -->listing all files ond folder in a directors.
cd docu / bio -->tab
cd -->enter
cd bio
(.)-->current directory.
Top comments (0)