Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix redundant spacing inside parentheses in tutorial code
  • Loading branch information
yakhyo committed Feb 25, 2026
commit a428f76d2aa9bb80c4ebeaef707a0f38a37a81d5
4 changes: 2 additions & 2 deletions tools/python-formatter.njk
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ permalink: /python-formatter/
</div>
<div class="bg-[#1e293b] flex-1 relative overflow-auto">
<pre class="h-full language-python"><code id="editor" class="language-python focus:outline-none p-4 block min-h-full" contenteditable="true" spellcheck="false"># Messy code example
def calculate( x,y ):
def calculate(x, y):
if x>y:
return x-y
else: return y-x
print( calculate( 10, 5 ))</code></pre>
print(calculate(10, 5))</code></pre>
</div>
</div>

Expand Down
10 changes: 5 additions & 5 deletions tutorial/basic/12-python-strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Assume string variable a is 'Hello' and variable b is 'Python', then below are t
| `+ ` | `a + b ` | will result into HelloPython Concatenation - Adds values on both sides of the operator |
| `* ` | `a*2` | will result into HelloHello Repetition - Creates new string, concatenating multiple copies of the same string |
| ` []` | `a[1]` | will result into e Slice - Gives character from the given index |
| `[ : ]` | `a[1:4]` | will result into ell Range Slice - Gives characters from the given range |
| `[:]` | `a[1:4]` | will result into ell Range Slice - Gives characters from the given range |
| `in` | `H in a ` | will result into 1 Membership - Returns true if a character exists in the given string |
| ` not in` | ` Z not in a` | will result into 1 Membership - Returns true if a character does not exist in the given string |
| `r/R ` | `print r'\n' prints \n and print R'\n'prints \n` | Raw String - Suppresses actual meaning of Escape characters. Syntax for raw strings is exactly same as normal strings except the raw string operator, letter "r", which precedes the quote. "R" can be lowercase (r) or uppercase (R) and must be placed immediately before the first quote. |
Expand Down Expand Up @@ -115,9 +115,9 @@ Here is an example:
```python
triplequotes = """this is a long string that is made up of
several lines and non-printable characters such as
TAB( \t ) and they will show up that way when displayed.
TAB(\t) and they will show up that way when displayed.
NEWLINEs within the string, whether explicitly given like
this within the brackets [ \n ], or just a NEWLINE within
this within the brackets [\n], or just a NEWLINE within
the variable assignment will also show up.
"""
print(triplequotes)
Expand Down Expand Up @@ -156,11 +156,11 @@ Python includes the following built-in methods to manipulate strings:
| `min(str)` | Returns the min alphabetic character from the string str. |
| `replace(old, new [, max])` | Replaces all occurrences of old in string with new or at most max occurrences if max given. |
| `rfind(str, beg = 0,end = len(string))` | Same as find(), but search backwards in string. |
| `rindex( str, beg = 0, end = len(string))` | Same as index(), but search backwards in string. |
| `rindex(str, beg = 0, end = len(string))` | Same as index(), but search backwards in string. |
| `rjust(width,[, fillchar])` | Returns a space-padded string with the original string right-justified to a total of width columns. |
| `rstrip()` | Removes all trailing whitespace of string. |
| `split(str="", num=string.count(str))` | Splits string according to delimiter str (space if not provided) and returns list of substrings; split into at most num substrings if given. |
| `splitlines( num=string.count('\n')) ` | Splits string at all (or num) NEWLINEs and returns a list of each line with NEWLINEs removed. |
| `splitlines(num=string.count('\n'))` | Splits string at all (or num) NEWLINEs and returns a list of each line with NEWLINEs removed. |
| `startswith(str, beg=0,end=len(string)` | Determines if string or a substring of string (if starting index beg and ending index end are given) starts with substring str; returns true if so and false otherwise. |
| `strip([chars])` | Performs both lstrip() and rstrip() on string |
| `swapcase()` | Inverts case for all letters in string. |
Expand Down
4 changes: 2 additions & 2 deletions tutorial/basic/14-python-lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Creating a list is very simple, just entering comma-separated values between squ
```python
#Simple example of creating list in python programming language
list1 = ['chemistry', 'physics', 1993, 2017]
list2 = [1, 2, 3, 4, 5 ]
list2 = [1, 2, 3, 4, 5]
list3 = ["a", "b", "c", "d"]
```

Expand All @@ -34,7 +34,7 @@ Here is an example of how to access values in a python list :
#Way to access value in Python list

list1 = ['physics', 'chemistry', 1993, 2017]
list2 = [1, 2, 3, 4, 5, 6, 7 ]
list2 = [1, 2, 3, 4, 5, 6, 7]

print("list1[0]: ", list1[0])
print("list2[1:5]: ", list2[1:5])
Expand Down
6 changes: 3 additions & 3 deletions tutorial/basic/16-python-tuples.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Creating a tuple is as easy as putting comma-separated values. Optionally, you c
#Simple example of creating tuple in python programming language

tup1 = ('physics', 'chemistry', 1993, 2017)
tup2 = (1, 2, 3, 4, 5 )
tup2 = (1, 2, 3, 4, 5)
tup3 = "a", "b", "c", "d"
```

Expand All @@ -31,7 +31,7 @@ To access values in a tuple, use square brackets for slicing along with the inde
#How to access tuple values

tup1 = ('physics', 'chemistry', 1993, 2017)
tup2 = (1, 2, 3, 4, 5, 6, 7 )
tup2 = (1, 2, 3, 4, 5, 6, 7)

print("tup1[0]: ", tup1[0])
print("tup2[1:5]: ", tup2[1:5])
Expand Down Expand Up @@ -91,7 +91,7 @@ In fact, Tuples respond to all of the general sequence operations we used on Str
| Python Expression | Result | Explanation |
| ----------------------------------------- | -------------------------------------- | ------------- |
| `len((1, 2, 3))` | `3` | Length |
| `(1, 2, 3) + (4, 5, 6) ` | `(1, 2, 3, 4, 5, 6)` | Concatenation |
| `(1, 2, 3) + (4, 5, 6)` | `(1, 2, 3, 4, 5, 6)` | Concatenation |
| `('Hello!',) \* 4` | `('Hello!', 'Hello!', 'Hello!', 'Hello!')` | Repetition |
| `3 in (1, 2, 3)` | `True` | Membership |
| `for x in (1,2,3) : print(x, end = ' ')` | `1 2 3` | Iteration |
Expand Down
2 changes: 1 addition & 1 deletion tutorial/basic/19-python-date-time.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ You can format any time as per your requirement, but simple method to get time i
```python
import time;

localtime = time.asctime( time.localtime(time.time()) )
localtime = time.asctime(time.localtime(time.time()))
print("Current local time :", localtime)
```

Expand Down
2 changes: 1 addition & 1 deletion tutorial/basic/20-python-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ You can define functions to provide the required functionality. Here are simple
Example of function

```python
def printme( str ):
def printme(str):
"This prints a passed string into this function"
print(str)
return
Expand Down
2 changes: 1 addition & 1 deletion tutorial/intermediate/22-python-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Simply put, a module is a file consisting of Python code. A module can define fu
Here is an example of a simple Python module:

```python
def print_func( par ):
def print_func(par):
print("Hello : ", par)
return
```
Expand Down
20 changes: 10 additions & 10 deletions tutorial/intermediate/26-python-database-access.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Below is an example of connection with MySQL database "TESTDB"
import pymysql.cursors

# Open database connection
db = pymysql.connect("localhost","testuser","test123","TESTDB" )
db = pymysql.connect("localhost", "testuser", "test123", "TESTDB")

# prepare a cursor object using cursor() method
cursor = db.cursor()
Expand All @@ -93,7 +93,7 @@ db.close()
import pymysql.cursors

# Open database connection
db = pymysql.connect("localhost","testuser","test123","TESTDB" )
db = pymysql.connect("localhost", "testuser", "test123", "TESTDB")

# prepare a cursor object using cursor() method
cursor = db.cursor()
Expand All @@ -107,7 +107,7 @@ sql = """CREATE TABLE EMPLOYEE(
LAST_NAME CHAR(20),
AGE INT,
SEX CHAR(1),
INCOME FLOAT )"""
INCOME FLOAT)"""

cursor.execute(sql)

Expand All @@ -123,7 +123,7 @@ The following example executes SQL INSERT statement to create a record into EMPL
import pymysql.cursors

# Open database connection
db = pymysql.connect("localhost","testuser","test123","TESTDB" )
db = pymysql.connect("localhost", "testuser", "test123", "TESTDB")

# prepare a cursor object using cursor() method
cursor = db.cursor()
Expand Down Expand Up @@ -151,15 +151,15 @@ The example above can be written as follows to create SQL queries dynamically
import pymysql.cursors

# Open database connection
db = pymysql.connect("localhost","testuser","test123","TESTDB" )
db = pymysql.connect("localhost", "testuser", "test123", "TESTDB")

# prepare a cursor object using cursor() method
cursor = db.cursor()

# Prepare SQL query to INSERT a record into the database.
sql = "INSERT INTO EMPLOYEE(FIRST_NAME, \
LAST_NAME, AGE, SEX, INCOME) \
VALUES('%s', '%s', '%d', '%c', '%d' )" % \
VALUES('%s', '%s', '%d', '%c', '%d')" % \
('Mac', 'Mohan', 20, 'M', 2000)
try:
# Execute the SQL command
Expand Down Expand Up @@ -192,7 +192,7 @@ The following procedure queries all records from EMPLOYEE table having salary mo
import pymysql.cursors

# Open database connection
db = pymysql.connect("localhost","testuser","test123","TESTDB" )
db = pymysql.connect("localhost", "testuser", "test123", "TESTDB")

# prepare a cursor object using cursor() method
cursor = db.cursor()
Expand All @@ -213,7 +213,7 @@ try:
income = row[4]
# Now print fetched result
print("fname = %s,lname = %s,age = %d,sex = %s,income = %d" % \
(fname, lname, age, sex, income ))
(fname, lname, age, sex, income))
except:
print("Error: unable to fetch data")

Expand All @@ -233,7 +233,7 @@ The following procedure updates all the records having SEX as 'M'. Here, we incr
import pymysql.cursors

# Open database connection
db = pymysql.connect("localhost","testuser","test123","TESTDB" )
db = pymysql.connect("localhost", "testuser", "test123", "TESTDB")

# prepare a cursor object using cursor() method
cursor = db.cursor()
Expand Down Expand Up @@ -261,7 +261,7 @@ DELETE Operation is required when you want to delete some records from your data
import pymysql.cursors

# Open database connection
db = pymysql.connect("localhost","testuser","test123","TESTDB" )
db = pymysql.connect("localhost", "testuser", "test123", "TESTDB")

# prepare a cursor object using cursor() method
cursor = db.cursor()
Expand Down