In this post, I will be regularly posting useful Python programming tips.
These tips will be organized in different categories, in order to make it easier to read it.
Hello World in Python
The below command, prints a “Hello World” message from within a Python script:
print("Hello World from Python")
Code Indentation in Python
In many programming languages, code indentation plays only a formatting role, however, in Python, code indentation is used for setting code blocks. Check for example the below if…else statement:
#if...elif...else example a=200 b=200 if a>b: print("a is greater than b") elif a==b: print("a and b are equal") else: print("b is greater than a")
As you can see, within each if, elif and else code blocks, I include one command in right indent.
This is an example of how code indentation is used in Python.
How to use Visual Studio Code for Python Development
Among the many IDE options you have for programming in Python, you can also use Visual Studio Code, which is a free IDE by Microsoft that supports developing in many programming languages.
So, after you have installed Visual Studio Code, you can find a free Python extension from its marketplace, install the extension and that’s it, you are ready to start developing in Python. In my setup, when developing in Python within Visual Studio Code, I use Microsoft’s Python extension.
In order of course to be able to run a Python script, you also need to install Python in your environment. You can find the available Python installers here.
Comments in Python
To comment a line of code in Python, you just need to use the # sign. Here’s an example:
#This is comment in Python
How to Easily Split a String in Python
In Python, you can split a string very easily. Check the below example:
string="Programming in Python" splitString=string.split() print(splitString) print(splitString) print(splitString) print(splitString)
More Python programming tips are coming soon!
Learn More about Python Programming and SQL Server Data Access
Enroll to our online course “Working with Python on Windows and SQL Server Databases” with an exclusive discount, and get started with Python data access programming for SQL Server databases, fast and easy!
Get Started with Programming Fast and Easy – Enroll to the Online Course!
Check our online course “Introduction to Computer Programming for Beginners” (special limited-time discount included in link).
Learn the philosophy and main principles of Computer Programming and get introduced to C, C++, C#, Python, Java and SQL.
Featured Online Courses:
- Working with Python on Windows and SQL Server Databases (New)
- Boost SQL Server Database Performance with In-Memory OLTP
- Essential SQL Server Administration Tips
- SQL Server Fundamentals – SQL Database for Beginners
- Essential SQL Server Development Tips for SQL Developers
- Introduction to Computer Programming for Beginners
- .NET Programming for Beginners – Windows Forms with C#
- Introduction to Data Science and SQL Server Machine Learning
- Introduction to Azure SQL Database for Beginners
- SQL Server 2019: What’s New – New and Enhanced Features
- Entity Framework: Getting Started – Complete Beginners Guide
- How to Import and Export Data in SQL Server Databases
- Learn How to Install and Start Using SQL Server in 30 Mins
- A Guide on How to Start and Monetize a Successful Blog
- How to Connect to SQL Server Databases from a Python Program
- Working with Python on Windows and SQL Server Databases (Course Preview)
- How to Resolve: [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)
- How to Write to a Text File from a C++ Program
- How to Establish a Simple Connection from a C# Program to SQL Server
- The timeout period elapsed prior to obtaining a connection from the pool
- Closing a C# Application (including hidden forms)
- Changing the startup form in a C# project
- Using the C# SqlParameter Object for Writing More Secure Code
- Cannot implicitly convert type ‘string’ to ‘System.Windows.Forms.DataGridViewTextBoxColumn
Subscribe to our newsletter and stay up to date!
Subscribe to our YouTube channel (SQLNetHub TV)
Easily generate snippets with Snippets Generator!
Secure your databases using DBA Security Advisor!
Generate dynamic T-SQL scripts with Dynamic SQL Generator!
Check our latest software releases!
Check our eBooks!
Rate this article:
Reference: SQLNetHub.com (https://www.sqlnethub.com)
Artemakis Artemiou is a Senior SQL Server Architect, Author, a 9 Times Microsoft Data Platform MVP (2009-2018) and a Udemy Instructor. He has over 15 years of experience in the IT industry in various roles. Artemakis is the founder of SQLNetHub and TechHowTos.com. Artemakis is the creator of the well-known software tools Snippets Generator and DBA Security Advisor. Also, he is the author of many eBooks on SQL Server. Artemakis currently serves as the President of the Cyprus .NET User Group (CDNUG) and the International .NET Association Country Leader for Cyprus (INETA). Moreover, Artemakis teaches on Udemy, you can check his courses here.