🌐
Reddit
reddit.com › r/learnpython › a bit of a dumb question… how does python know which are the rows and columns – please be nice to me. :d
r/learnpython on Reddit: A bit of a dumb question… How does python know which are the rows and columns – Please be nice to me. :D
February 15, 2023 -

So I know this will likely be a simple answer to this question, but I'm learning some basic python and just did a lesson where you learn to create what looks like tic-tac-toe fields by defining a function and using for loops.

Here is the code:

def drawField(): #we define a funtion using def.
    for row in range (5): #01234
        if row%2 == 0: # if the row is even
            for column in range (5): #Then for rows in the range 5(0,1,2,3,4)
                if column%2 ==0: #(if the column is even)
                    if column!=4: # and not equal to 4
                        print(" ", end ="") #print a space and add the next string. Do not add a new line. 
                    else:
                        print(" ") #or else for rows that are equal to 4, just print a space and end by starting a new line.
                else:
                    print("|", end = "") #For rows that are uneven print | and don't start a new line but continue in the same line. 
        else:
            print("-----") #For all uneven rows just print --------
drawField() #call the drawfield function.

The comments are me going through the code to make sure I know exactly what is happening.

I know it's probably dumb, but at first, I really thought row and column might be keywords that the language recognises, despite having learned about variables. Anyway, just to confirm, I changed the variables to simple letters and I still got my result.

What I'm thinking as I'm writing this is that initially, it's just two normal numeric series and then the end="" parameter is what actually determines the layout. Yeah, that sounds right to me actually but I would appreciate any confirmation because I could be totally off haha.

Thanks in advance!

Top answer
1 of 5
2
What I'm thinking as I'm writing this is that initially, it's just two normal numeric series and then the end="" parameter is what actually determines the layout. Yeah, that sounds right to me actually but I would appreciate any confirmation because I could be totally off haha. Yep... pretty much this. The printing order on the screen is set, you ask python to print something, it goes from left to right, and then the next row. You can't(*) first draw the last line, and then move upwards, or print a character, and move to its left to add another... So the entire loop needs to prepare prints in that specific order. EDIT: * - actually can, but its more complex.
2 of 5
1
See if restructuring your code this way helps you make sense of it: def odd_row_string(): return '-----' def even_row_string(): return ' | | ' def even_row_string_the_long_way(): string = '' for column in range(5): if column % 2 == 0: string = string + ' ' else: string = string + '|' return string def drawField(): for row in range(5): if row%2 == 0: string = even_row_string_the_long_way() else: string = odd_row_string() print(string) drawField() Those two versions of the function that makes the even row string give exactly the same output. Part of your confusion is from having a needlessly nested loop structure when you could just build the lines of text you want to print with one line of code each, and part of your confusion is from trying to print single characters at a time and messing with the end-of-line parameters, avoid that by passing whole lines to the print() function.
🌐
Apache
spark.apache.org › docs › latest › api › python › reference › pyspark.sql › api › pyspark.sql.Row.html
pyspark.sql.Row — PySpark 4.2.0 documentation
Row can be used to create a row object by using named arguments. It is not allowed to omit a named argument to represent that the value is None or missing.
🌐
Rows
rows.com › docs › how-to-use-python-in-rows
Using Python in Rows | Rows
Rows now supports Python scripting within your spreadsheets, giving you the flexibility to process data, automate calculations, and integrate with external APIs—all from within your familiar Rows environment.
🌐
AskPython
askpython.com › python-modules › pandas › dataframe-rows-and-columns
Working with DataFrame Rows and Columns in Python - AskPython
February 16, 2023 - Python, being a language widely used for data analytics and processing, has a necessity to store data in structured forms, say as in our conventional tables in the form of rows and columns. We use the DataFrame object from the Pandas library of python to achieve this.
🌐
PyPI
pypi.org › project › rows
rows · PyPI
No matter in which format your tabular data is: rows will import it, automatically detect types and give you high-level Python objects so you can start working with the data instead of trying to parse it. It is also locale-and-unicode aware.
      » pip install rows
    
Published: Feb 14, 2019
Version: 0.4.1
🌐
pytz
pythonhosted.org › trustedanalytics › ds_apir.html
Python User Functions — Trusted Analytics Platform 0.6.0 documentation
The Row object is a read-only dictionary-like structure which contains the cell values for a particular row. The values are accessible using the column name, with typical Python square bracket lookup, as shown in the example above.
Find elsewhere
🌐
Real Python
realpython.com › videos › rows-columns-pandas-datafram
Working With Rows and Columns in DataFrames (Video) – Real Python
A frequent operation that you’ll be doing on a DataFrame is to extract rows or columns. Let’s start with accessing, say, a column. Let’s access this city column. Here, you’re going to be using notation that’s similar to a Python dictionary. So in…
Published: July 27, 2021
🌐
Note.nkmk.me
note.nkmk.me › home › python › pandas
pandas: Select rows/columns by index (numbers and names) | note.nkmk.me
August 8, 2023 - You can select and get rows, columns, and elements in pandas.DataFrame and pandas.Series by index (numbers and names) using [] (square brackets).
🌐
Readthedocs
row.readthedocs.io › en › 0.3.1 › guide › python › index.html
Using row with Python and signac - Row documentation
This section explains how to use row effectively with signac projects and one suggested way to structure action commands in a Python file.
🌐
GitHub
github.com › turicas › rows
GitHub - turicas/rows: A common, beautiful interface to tabular data, no matter the format · GitHub
No matter in which format your tabular data is: rows will import it, automatically detect types and give you high-level Python objects so you can start working with the data instead of trying to parse it. It is also locale-and-unicode aware.
Author: turicas
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-get-column-and-row-names-in-dataframe
How to get column and row names in DataFrame? - GeeksforGeeks
July 15, 2025 - Python3 · # iterate the indices and print each one for row in data.index: print(row, end = " ") Output: Now, let's print the total count of the index.
🌐
Rows
rows.com › docs › functions › python
Rows | PYTHON function
Use PYTHON to execute custom Python scripts on one or more cell ranges in your doc. ... Use the Actions Wizard to configure any action in Rows without functions.