DEV Community

Sandeep
Sandeep

Posted on

Python Cheat Sheet Part - 1

Basics
Basic syntax from the python programming language

Showing Output To User
The print function is used to display or print output as follows

print("Content that you wanna print on screen")
Enter fullscreen mode Exit fullscreen mode

Taking Input From the User
The input function is used to take input from the user as follows:

var = input("Enter your name: ")
Enter fullscreen mode Exit fullscreen mode

Empty List
This method allows you to create an empty list

my_list = []
Enter fullscreen mode Exit fullscreen mode

Empty Dictionary
By putting two curly braces, you can create a blank dictionary

my_dict = {}
Enter fullscreen mode Exit fullscreen mode

range Function
range function returns a sequence of numbers, eg, numbers starting from 0 to n-1 for range(0, n)

range(int_value)
Enter fullscreen mode Exit fullscreen mode

Comments
Comments are used to make the code more understandable for programmers, and they are not executed by compiler or interpreter.

Single line comment

# This is a single line comment
Enter fullscreen mode Exit fullscreen mode

Multi-line comment

'''This is a
multi-line
comment'''
Enter fullscreen mode Exit fullscreen mode

Escape Sequence
An escape sequence is a sequence of characters; it doesn't represent itself (but is translated into another character) when used inside string literal or character. Some of the escape sequence characters are as follows:

Newline
Newline Character

\n
Enter fullscreen mode Exit fullscreen mode

Backslash
It adds a backslash

\\
Enter fullscreen mode Exit fullscreen mode

Single Quote
It adds a single quotation mark

\'
Enter fullscreen mode Exit fullscreen mode

Tab
It gives a tab space

\t
Enter fullscreen mode Exit fullscreen mode

Backspace
It adds a backspace

\b
Enter fullscreen mode Exit fullscreen mode

Octal value
It represents the value of an octal number

\ooo
Enter fullscreen mode Exit fullscreen mode

Hex value
It represents the value of a hex number

\xhh
Enter fullscreen mode Exit fullscreen mode

Carriage Return
Carriage return or \r will just work as you have shifted your cursor to the beginning of the string or line.

\r
Enter fullscreen mode Exit fullscreen mode

Top Websites to learn Python

How to install python in windows 10

Best IDE's for Python

Discussion (2)

Collapse
vpgmackan profile image
Mackan

Those are really good even if I know a lot of Python. Thanks!!

Collapse
sandeepk27 profile image
Sandeep Author

Thank you for the support