Top 10 Programming Language to learn in 2023

Are you a programming enthusiast looking to stay ahead of the curve in 2023? With the ever-evolving tech landscape, keeping up with the Best Programming Language to learn can be a daunting task. Fear not, as we have compiled a list of the top 10 Programming Languages that you should consider learning in 2023. Python: This versatile language continues to dominate in 2023, with its ease of use, readability, and a vast library of modules. JavaScript: As web development grows increasingly popular, JavaScript remains a crucial player, with its ability to create dynamic and interactive web pages. Java: This language has stood the test of time and remains a popular choice for enterprise software development. C++: A staple in the gaming and systems development industries, C++ offers exceptional performance and memory management. Swift: Apple's preferred language for iOS app development, Swift continues to grow in popularity with its simplicity and reliability. R: As data science and machin

Function In Python Programming | Python Programming


What is a function in Python?

In Python, a function is a group of related statements that perform a specific task.
Functions help break our program into smaller and modular chunks. As our program grows larger and larger, functions make it more organized and manageable.
Furthermore, it avoids repetition and makes code reusable.
You can define functions to provide the required functionality. Here are simple rules to define a function in Python.
  1. Function blocks begin with the keyword def followed by the function name and parentheses ( ( ) ).
  2. Any input parameters or arguments should be placed within these parentheses.
  3. You can also define parameters inside these parentheses.
  4. The first statement of a function can be an optional statement – the documentation string of the function or docstring.
  5. The code block within every function starts with a colon (:) and is indented.
  6. The statement return [expression] exits a function, optionally passing back an expression to the caller. A return statement with no arguments is the same as return None.


Syntax of Function

def function_name(parameters):
        """docstring"""
        statement(s)
  1. Above shown is a function definition which consists of following components.
  2. Keyword def marks the start of the function header.
  3. A function name to uniquely identify it. Function naming follows the same rules of writing identifiers in python.
  4. Parameters (arguments) through which we pass values to a function. They are optional.
  5. A colon (:) to mark the end of the function header.
  6. Optional documentation string (docstring) to describe what the function does.
  7. One or more valid python statements that make up the function body. Statements must have the same indentation level (usually 4 spaces).
  8. An optional return statement to return a value from the function.


Example of a function

   def greet(name):
    """This function greets to
    the person passed in as
    parameter"""
    print("Hello, " + name + ". Good morning!")

How to call a function in python?

Once we have defined a function, we can call it from another function, program or even the Python prompt. To call a function we simply type the function name with appropriate parameters.
>>> greet('Paul')
Hello, Paul. Good morning!
Note: Try running the above code into the Python shell to see the output.

Docstring


The first string after the function header is called the docstring and is short for documentation string. It is used to explain in brief, what a function does.
Although optional, documentation is a good programming practice. Unless you can remember what you had for dinner last week, always document your code.
In the above example, we have a docstring immediately below the function header. We generally use triple quotes so that docstring can extend up to multiple lines. This string is available to us as the __doc__ attribute of the function.
For example:
Try running the following into the Python shell to see the output.
  1. >>> print(greet.__doc__)
  2. This function greets to
  3. the person passed into the
  4. name parameter


Popular posts from this blog

C program to Find Cartesian Product of Two Sets | C programming

Array in C Programming | C Programming

What is System? | SAD