Python
  • Getting Started
    • Input and Output
    • Variables
    • Data Types
    • Conditional Structures
      • Humidity Level
      • Financial Transactions
      • Fruit-Vending Machine
      • Magic While
      • FizzBuzz
    • Functions
      • Hashtag Generator
  • Data Structures
    • Lists
    • Dictionary
    • Set
    • Interpreter Expressions
  • OOPs
    • Classes and Objects
    • Exception Handling
      • Simple Calculator
  • System Programming
    • File Operations
    • Directory Navigation
    • Process Creation
    • Threads
Powered by GitBook
On this page
  • Output using print() function
  • More on using print()
  • Walrus Operator :=
  • Importing Sys for User Inputs
  1. Getting Started

Input and Output

I LOVE DOING THIS :)

In Python 2, you have a built-in function raw_input(), whereas in Python 3, you have input(). The program will resume once the user presses the ENTER key.

>>> raw_input()
I am learning python 2
>>> input()
I am learning python 3

Output using print() function

>>> print "Python 2"
Python 2

>>> print("Python 3")
Python 3

More on using print()

>>> print("5"*6)
555555

>>> print(5,6,7)
5 6 7

>>> print('LOVE', 30, 82.2)
LOVE 30 82.2

>>> print('LOVE', 30, 82.2, sep=',')
'LOVE', 30, 82.2

By default, print goes to a new line at the end. You can change this by using the keyword end

>>> print('LOVE', 30, 82.2, sep=',', end='!!\n')
'LOVE', 30, 82.2!!

You can change this default implementation. You can have a colon : between the letters instead of a new line

>>> for i in "python" :
       print(i, end=':')

p:y:t:h:o:n:

Walrus Operator :=

This Operator allows you to assign values to variables within an expression

# Instead of this !!
>>> num = int(input())
>>> print(num)
# Use this !!
>>> print(num:=int(input()))

Importing Sys for User Inputs

The sys module provides various functions and variables. It allows operating on the interpreter as it provides access to the variables and functions that interact strongly with the interpreter

>>> name = sys.argv[1]
Akash
>>> print(name)
Akash
NextVariables

Last updated 2 years ago