Functions with Return Statement in Python | Python Tutorials for Beginners #lec73

Functions with Return Statement in Python | Python Tutorials for Beginners #lec73

Introduction to Functions with Return Values

Overview of Previous Discussions

  • The series has previously covered basic concepts in Python, including functions without arguments and various types of arguments such as keyword, positional, and arbitrary arguments.

Introduction to Functions with Return Values

  • This video focuses on functions that return values to the caller, a topic not yet discussed in previous videos.

Types of Return Statements

  • The discussion will include different types of return statements: implicit and explicit returns. Examples and practical programming demonstrations will be provided.

Career Opportunities in Data Science

Salary Calculator Introduction

  • A salary calculator is introduced for viewers interested in data science careers. Users can input their details to receive an estimated salary based on their qualifications.

Odin School Boot Camp Details

  • Odin School offers a six-month data science boot camp aimed at providing industry-aligned education at an affordable price.

Financial Assistance Options

  • Scholarships up to ₹30,000 are available through a scholarship test, along with early bird discounts and no-cost EMI options.

Placement Support Information

  • Placement support begins from the sixth month and continues until the twelfth month. Success stories from past students can be accessed for credibility.

Understanding Function Definitions

Basics of Function Definition

  • Functions are defined using the def keyword followed by the function name and parameters. The body contains statements that perform specific tasks when executed.

Calling Functions

  • To execute a function, it must be called by its name along with any required arguments.

Example: Adding Two Numbers

  • An example is given where a function named ADD takes two parameters (5 and 4), demonstrating how parameters differ from arguments during function calls.

Returning Values from Functions

  • Instead of printing results directly within the function, using return allows the function to send back calculated values (e.g., returning 9 for 5 + 4).

Storing Returned Values

  • When calling a function that returns a value, it should be stored in a variable for further use or display (e.g., storing output from add(5, 4)).

This structured approach provides clarity on key topics discussed throughout the transcript while ensuring easy navigation through timestamps linked directly to relevant sections of the video content.

Understanding Return Values in Functions

Introduction to Return Values

  • Functions accept arguments, process them, and return a value to the caller. This returned value is known as the return value.
  • There are two types of return values: explicit and implicit. The video will discuss these types in detail later.

Syntax of Return Statement

  • A return statement is special and can only be used inside a function; using it outside will result in a syntax error.
  • The syntax for a return statement includes the return keyword followed by an optional return value. If omitted, it defaults to returning None.

Types of Return Values

  • In Python, any object can be returned from a function, including numeric values (int, float), collections (list, tuple, set, dictionary), or even user-defined functions and modules.
  • You can either use a complete return statement with a value or simply use return without specifying anything.

Practical Example: Addition Function

  • An example function named add takes two parameters (A and B), calculates their sum (C), and prints it.
  • To modify this function to return the sum instead of printing it, you would use return C, which sends the calculated value back to the caller.

Handling Returned Values

  • If you want to see the output after returning a value, you must print it or store it in another variable.
  • You can simplify your code by directly returning the expression (return A + B) instead of storing it first.

Implicit Returns

  • If no return value is specified after using return, Python returns None. Omitting both the line and keyword also results in an implicit None being returned.
  • Explicit returns specify what is being returned while implicit returns default to None if nothing is specified.

Importance of Placement for Return Statements

  • The placement of the return statement matters; it must be within a function definition. Using it outside will lead to syntax errors.

Exercise: Formatting Names into Title Case

  • As an exercise, viewers are encouraged to create a function that formats names into title case where each word's first letter is capitalized.
  • The task involves defining a new function called format_name, which takes two parameters (first name and last name).

How to Format Names in Title Case

Formatting Names with Title Case

  • The process begins by converting names into title case, ensuring that both first and last names are formatted correctly.
  • Instead of returning values directly, the initial approach involves printing the first name and last name as they are, which does not apply formatting.
  • A new variable is introduced to store the formatted first name, indicating a shift towards better organization in code.
  • The formatted names are printed together; however, adjustments are made to ensure proper capitalization (e.g., "Jenny Katri" instead of "jenny katri").
  • The discussion transitions from printing to returning values. A variable named formatted_name is created for easier handling of the returned string.

Understanding Return Values in Functions

  • The concept of return values is clarified: functions can return various types of data (numeric, collections, strings), emphasizing flexibility in programming.
  • The importance of using the return keyword is highlighted as a means to output function results effectively.
Video description

Salary Calculator Link: https://hubs.la/Q01VfkdB0 OdinSchool Data Science Course Link: https://hubs.la/Q01Vfk-p0 Best Python Tutorials for Beginners: https://www.youtube.com/playlist?list=PLdo5W4Nhv31bZSiqiOL5ta39vSnBxpOPT ********************************************* Connect & Contact Me: Jenny's Lectures HINDI: https://www.youtube.com/@JennyslecturesHINDI Facebook: https://www.facebook.com/Jennys-Lectures-CSIT-Netjrf-316814368950701/ Quora: https://www.quora.com/profile/Jayanti-Khatri-Lamba Instagram: https://www.instagram.com/jayantikhatrilamba/ Twitter: https://twitter.com/KhatriJenny ******************************************* More Playlists: Programming in C Tutorials: https://www.youtube.com/playlist?list=PLdo5W4Nhv31a8UcMN9-35ghv8qyFWD9_S Printing Pattern in C: https://www.youtube.com/playlist?list=PLdo5W4Nhv31Yu1igxTE2x0aeShbKtVcCy C++ Tutorials for beginners: https://www.youtube.com/watch?v=KYxLEDF6kjs&list=PLdo5W4Nhv31YU5Wx1dopka58teWP9aCee Placement Series: https://www.youtube.com/playlist?list=PLdo5W4Nhv31YvlDpJhvOYbM9Ap8UypgEy Data Structures and Algorithms: https: https://www.youtube.com/playlist?list=PLdo5W4Nhv31bbKJzrsKfMpo_grxuLl8LU Design and Analysis of Algorithms(DAA): https://www.youtube.com/playlist?list=PLdo5W4Nhv31ZTn2P9vF02bkb3SC8uiUUn Dynamic Programming: https://www.youtube.com/playlist?list=PLdo5W4Nhv31aBrJE1WS4MR9LRfbmZrAQu Operating Systems tutorials: //www.youtube.com/playlist?list=PLdo5W4Nhv31a5ucW_S1K3-x6ztBRD-PNa DBMS Tutorials: https://www.youtube.com/playlist?list=PLdo5W4Nhv31b33kF46f9aFjoJPOkdlsRc best channel to learn programming python jennys lectures jennys lectures ds jayanti khatri lamba jenny lamba data structure and algorithms data structure tutorials jenny data structures data science Data Science full course data science for beginners odin school odin school data science data science course data science tutorial data science training introduction to data science data science tutorial for beginners data scientist what is data science Learn Data Science data science career 6 months free training free data science certificate data science certification course free courses career upgrade career relaunch career change