DEV Community

Lakshmi Pritha Nadesan
Lakshmi Pritha Nadesan

Posted on

Day 4 - None Datatype & input() function in Python

None Datatype:

The Python NoneType is a data type that represents the absence of a value. In Python, the NoneType is represented by the keyword "None".

Example:
In this example When you run the code, it will display "hello".

def display():
    print("hello")
display()
Enter fullscreen mode Exit fullscreen mode

Output:

hello
Enter fullscreen mode Exit fullscreen mode

Example 2:

The None is printed because that's the default return value of a function that doesn't have an explicit return statement.

def display():
    print("hello")
print(display())
Enter fullscreen mode Exit fullscreen mode

Output:

hello
None
Enter fullscreen mode Exit fullscreen mode

Example 3:

"hello" is printed by the print() inside the function.
30 is printed by the print() outside the function, which displays the value returned by display().

def display():
    print("hello")
    return 10+20
print(display())

Enter fullscreen mode Exit fullscreen mode

Output:

hello
30
Enter fullscreen mode Exit fullscreen mode

input() function:
The builtin function input() in Python takes input from a user and returns it as a string by default.

Example:

name = input("Enter your name: ")
print("Welcome to Python", name)
print(type(name))

Enter fullscreen mode Exit fullscreen mode

Output:

Enter your name: Pritha
Welcome to Python Pritha
<class 'str'>


Enter fullscreen mode Exit fullscreen mode

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (1)

Collapse
 
abdallah_gamilali_d316a1 profile image
Comment hidden by post author

Some comments have been hidden by the post's author - find out more

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay