cft

Python 3 quick start guide (Python cheat sheet)

Python 3 is a truly versatile programming language, loved both by web developers, data scientists and software engineers. And there are several good reasons for that!


user

Harendra Verma

a year ago | 2 min read

Python 3 is a truly versatile programming language, loved both by web developers, data scientists and software engineers. And there are several good reasons for that!

• Python is open-source and has a great support community,
• Plus, extensive support libraries.
• Its data structures are user-friendly.

Once you get a hang of it, your development speed and productivity will soar!

Table of Contents

  1. Python Basics: Getting Started
  2. Main Python Data Types
  3. How to Create a String in Python
  4. Math Operators
  5. How to Store Strings in Variables
  6. Built-in Functions in Python
  7. How to Define a Function
  8. List
  9. List Comprehensions
  10. Tuples
  11. Dictionaries
  12. If Statements (Conditional Statements) in Python
  13. Python Loops
  14. Class
  15. Dealing with Python Exceptions (Errors)
  16. How to Troubleshoot the Errors
  17. Conclusion

Python Basics: Getting Started

Most Windows and Mac computers come with Python pre-installed. You can check that via a Command Line search. The particular appeal of Python is that you can write a program in any text editor, save it in .py format and then run via a Command Line. But as you learn to write more complex code or venture into data science, you might want to switch to an IDE or IDLE.

What is IDLE (Integrated Development and Learning)

IDLE (Integrated Development and Learning Environment) comes with every Python installation. Its advantage over other text editors is that it highlights important keywords (e.g. string functions), making it easier for you to interpret code.
Shell is the default mode of operation for Python IDLE. In essence, it’s a simple loop that performs that following four steps:

• Reads the Python statement
• Evaluates the results of it
• Prints the result on the screen
• And then loops back to read the next statement.

Python shell is a great place to test various small code snippets.

Main Python Data Types

Every value in Python is called an “object”. And every object has a specific data type. The three most-used data types are as follows:
Integers (int) — an integer number to represent an object such as “number 3”.
Integers => -2, -1, 0, 1, 2, 3, 4, 5

Floating-point numbers (float) — use them to represent floating-point numbers.
Floating-point numbers => -1.25, -1.0, --0.5, 0.0, 0.5, 1.0, 1.25

Strings — codify a sequence of characters using a string. For example, the word “hello”. In Python 3, strings are immutable. If you already defined one, you cannot change it later on.

While you can modify a string with commands such as replace() or join(), they will create a copy of a string and apply modification to it, rather than rewrite the original one.

Strings => ‘yo’, ‘hey’, ‘Hello!’, ‘what’s up!’

Plus, another three types worth mentioning are lists, dictionaries, and tuples. All of them are discussed in the next sections. For now, let’s focus on the strings.

How to Create a String in Python

You can create a string in three ways using single, double or triple quotes. Here’s an example of every option:

my_string = “Let’s Learn Python!”
another_string = ‘It may seem difficult first, but you
can do it!’
a_long_string = ‘’’Yes, you can even master multi-line
strings
that cover more than one line
with some practice’’’

IMP! Whichever option you choose, you should stick to it and use it consistently within your program.
As the next step, you can use the print() function to output your string in the console window. This lets you review your code and ensure that all functions well. Here’s a snippet for that:

Click here to read full article

Upvote


user
Created by

Harendra Verma

Software Developer

Currently I am working as a Full-stack developer and I have expertise with Python, Angular , PHP, Node JS, Laravel, Codeigniter and Front end.


people
Post

Upvote

Downvote

Comment

Bookmark

Share


Related Articles