name = input("What is your name?") print("Welcome to Python", name)
Use text editor to type syntax and save with extension .py and then to run this syntax in desktop page right click and select Open in Terminal
To run the program enter python3 (file name).py,Then click enter and enter a name.So that program will run.
Input name = input("What is your name?") print("Welcome to Python", name) Output What is your name?Guru Welcome to Python Guru
Functions:செயல்கூறு(Actions)
What is function?
Set of instructions for achieving a specific task with a name.
Example:
Watching_Meyyazhagan:
1. Laptop On
2. Netflix
3. Meyyazhagan
4. Play
Now in this above example for watching meyyazhagan movie the set of instructions are to be done like laptop on, open netflix, click meyyazhagan, Then click play button, But for instant we can say watching meyyazhagan which is a name includes all these set of actions.
()-Brackets represent some action is to be done. Inside brackets if anything is specified it is called as arguments or parameters,which is used to perform that function(action).Even without any arguments also a function can be performed.
ex:
eat(food)
sleep()
walk()
cook(rice, water)
swim(dress, pool)
write_exam(hallticket, pen, paper, pencil, scale, rubber, question_paper)
*Supporting Arguments: Comma Separated arguments.
input(),print()-Before brackets what action to be done will be mentioned in this input,print are functions to be performed.
Why function is required?
It is reusable code.No need to mention the full actions again and again we can use just one function.As already said example of watching meyyazhagan contains various actions to be done but we can just say watching_meyyazhagan.
Functions criteria:
- Function name should be meaningful.
- It should action names not just object name like laptop.
- It should not be in numbers.
- It should not contain space.
- Only "_" special character is allowed, not other special characters.
Types of functions:
predefined-Set of functions which are predefined while creating this language.Ex:input(),print().
Userdefined-set of functions which we can define whenever required.
Ex:
#Function Definition def calculate(no1,no2):#parameter / argument print(no1+no2) print(no1-no2) print(no1*no2) print(no1/no2) no1 = 120 no2 = 40 calculate(no1,no2) #Function Calling Statement
The above mentioned user defined function can also be done without user defined function "calculate" as following.
no1 = 100 no2 = 5 print(no1+no2) print(no1-no2) print(no1*no2) print(no1/no2)
But the problem is in this every time we have to enter the action to be done. If we have defined function it will be easy to perform by python.
The above is the detailed content of Python Day Functions-Meaning & types, Data type. For more information, please follow other related articles on the PHP Chinese website!

TomergelistsinPython,youcanusethe operator,extendmethod,listcomprehension,oritertools.chain,eachwithspecificadvantages:1)The operatorissimplebutlessefficientforlargelists;2)extendismemory-efficientbutmodifiestheoriginallist;3)listcomprehensionoffersf

In Python 3, two lists can be connected through a variety of methods: 1) Use operator, which is suitable for small lists, but is inefficient for large lists; 2) Use extend method, which is suitable for large lists, with high memory efficiency, but will modify the original list; 3) Use * operator, which is suitable for merging multiple lists, without modifying the original list; 4) Use itertools.chain, which is suitable for large data sets, with high memory efficiency.

Using the join() method is the most efficient way to connect strings from lists in Python. 1) Use the join() method to be efficient and easy to read. 2) The cycle uses operators inefficiently for large lists. 3) The combination of list comprehension and join() is suitable for scenarios that require conversion. 4) The reduce() method is suitable for other types of reductions, but is inefficient for string concatenation. The complete sentence ends.

PythonexecutionistheprocessoftransformingPythoncodeintoexecutableinstructions.1)Theinterpreterreadsthecode,convertingitintobytecode,whichthePythonVirtualMachine(PVM)executes.2)TheGlobalInterpreterLock(GIL)managesthreadexecution,potentiallylimitingmul

Key features of Python include: 1. The syntax is concise and easy to understand, suitable for beginners; 2. Dynamic type system, improving development speed; 3. Rich standard library, supporting multiple tasks; 4. Strong community and ecosystem, providing extensive support; 5. Interpretation, suitable for scripting and rapid prototyping; 6. Multi-paradigm support, suitable for various programming styles.

Python is an interpreted language, but it also includes the compilation process. 1) Python code is first compiled into bytecode. 2) Bytecode is interpreted and executed by Python virtual machine. 3) This hybrid mechanism makes Python both flexible and efficient, but not as fast as a fully compiled language.

Useaforloopwheniteratingoverasequenceorforaspecificnumberoftimes;useawhileloopwhencontinuinguntilaconditionismet.Forloopsareidealforknownsequences,whilewhileloopssuitsituationswithundeterminediterations.

Pythonloopscanleadtoerrorslikeinfiniteloops,modifyinglistsduringiteration,off-by-oneerrors,zero-indexingissues,andnestedloopinefficiencies.Toavoidthese:1)Use'i


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Atom editor mac version download
The most popular open source editor

Dreamweaver CS6
Visual web development tools
