Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

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 modeExit 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 modeExit fullscreen mode

Empty List
This method allows you to create an empty list

my_list = []
Enter fullscreen modeExit fullscreen mode

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

my_dict = {}
Enter fullscreen modeExit 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 modeExit 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 modeExit fullscreen mode

Multi-line comment

'''This is amulti-linecomment'''
Enter fullscreen modeExit 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 modeExit fullscreen mode

Backslash
It adds a backslash

\\
Enter fullscreen modeExit fullscreen mode

Single Quote
It adds a single quotation mark

\'
Enter fullscreen modeExit fullscreen mode

Tab
It gives a tab space

\t
Enter fullscreen modeExit fullscreen mode

Backspace
It adds a backspace

\b
Enter fullscreen modeExit fullscreen mode

Octal value
It represents the value of an octal number

\ooo
Enter fullscreen modeExit fullscreen mode

Hex value
It represents the value of a hex number

\xhh
Enter fullscreen modeExit 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 modeExit fullscreen mode

Top Websites to learn Python

How to install python in windows 10

Best IDE's for Python

Top comments(2)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
vpgmackan profile image
Mackan
Hi, I am a 14-year-old guy coder that loves making dumb stuff. Working on my dream project Budget Cat
  • Location
    Sweden
  • Joined

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

CollapseExpand
 
sandeepk27 profile image
Sandeep
Developer 🧑‍🎓 Passionate about Web Development, Python Development and open-source. Book lover 📔 || Music Lover 🎶 || 💻 Internet surfer 🏄
  • Location
    Hyderabad, India
  • Education
    Master's in Computer Applications
  • Work
    Data Engineer
  • Joined

Thank you for the support

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Developer 🧑‍🎓 Passionate about Web Development, Python Development and open-source. Book lover 📔 || Music Lover 🎶 || 💻 Internet surfer 🏄
  • Location
    Hyderabad, India
  • Education
    Master's in Computer Applications
  • Work
    Data Engineer
  • Joined

More fromSandeep

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp