How To Use 2 Variables In For Loop In Python (Code Examples)

The for loop in Python allows the user to iterate through a variable that is iterable, such as a list. In Python the syntax for the loop is simply: for x in my_list: and you’re off looping through each element in my_list. But how do you access the index number of the element? In other programming languages, such as JavaScript, looping involves just the index number: 1 2 3 for (var i = 0; i < my_list.length; i += 1) { var elem = my_list[i] } But what would be Python’s equivalent? ...

November 9, 2021 · 3 min · 487 words · Ryan Sheehy

How To Print A Tab In Python

How do you print a tab character in Python? The easiest way to print a tab character in Python is to use the short-hand abbreviation '\t' (don’t forget the quotation marks – it needs to be parked inside a string). To see the tab-spaced character in the REPL output pane, wrap any variable containing a tab character in the built-in print() function. Here’s a simple example: 1 2 3 >>> my_tabbed_string = 'Space\tman' >>> print(my_tabbed_string) Space man What if you’d prefer to see the tab character instead of the actual spacing? ...

November 7, 2021 · 3 min · 528 words · Ryan Sheehy

How To Print A List In Python (And With Custom Formatting)

When you want to print the contents of a list you have a couple of different options depending upon the context. If you’re in the REPL there’s the easy method of entering the name of the variable storing the list, to the option of using the standard print function. If you’re within a script file the best option would be to use the print function, or if you want to import the sys library to write the equivalent of print by using sys.stdout.write(). ...

November 5, 2021 · 4 min · 752 words · Ryan Sheehy

Add Formula In Excel: Examples

What is the formula to add in Excel? There are two popular ways to add numbers together in Excel: using the plus sign + or using the SUM formula. Use the + sign where values being added are manually entered, and use SUM when referencing specific cell values. Here are some examples demonstrating the use of each type: When To Use + (Plus) Sign In a spreadsheet the plus sign can be used in the same way you use a calculator. However, to get the spreadsheet to begin adding the numbers you must prompt the cell by entering an equal sign =. This triggers the spreadsheet to know that it will need to do a calculation with what you’re about to enter. ...

October 27, 2021 · 5 min · 929 words · Ryan Sheehy

How To Separate Characters Into Cells In Excel

If a cell contains words it can be easy to split these into individual cells using the Text to columns feature in Excel. Simply select the cells you want to split into multiple columns, navigate to the Data menu then click on the Text to Columns button. From this Text Wizard window select Delimited width (click Next >), then set the delimiter type to Space (click Next >) then click Finish. ...

October 27, 2021 · 3 min · 598 words · Ryan Sheehy

How Do You Type A + (Plus) In Excel?

When you start entering text into a cell and the first character of that cell is a plus symbol (+) you will get an error #NAME? and you would have noticed the cell changed to =+A. So how can you just display a cell with a plus sign? A 1 #NAME? =+A Result after starting cell with + To display a cell that starts with a plus sign (+) enter the symbol that lets the spreadsheet know you’re entering text by starting with the single apostrophe (') then entering your plus symbol and whatever ever text next. For example, your cell would now contain '+A. ...

October 25, 2021 · 3 min · 626 words · Ryan Sheehy

How To Get Rid Of E+(Number) In Excel

When using large numbers in Excel or any other spreadsheet application, such as Google Sheets, some cells may display a number in scientific notation like 9.991E+35. How do you get rid of that E+n bit, where n is some number, in the cell? A 1 9.997E+11 =9999^3 Large number in cell The easiest way to change a number being displayed as E+n (where n is a number) is to right-click on the cell, click on the context menu item Format cells and then in the Number tab and the Category section select the option of Number. ...

October 25, 2021 · 5 min · 856 words · Ryan Sheehy

Python Increment By 1

How do you increase a variable by one in Python? In other popular programming languages to increment a variable by one you can use the simple increment syntax of ++, for example i++ will make the value of i increase by 1, but how do you do this in Python? To increment a variable in Python use the syntax += 1, for example to increment the variable i by 1 write i += 1. This is the shorter version of the longer form syntax i = i + 1. ...

October 24, 2021 · 6 min · 1079 words · Ryan Sheehy

Transpose A List Of Lists: Python Examples, No Imports

When using a spreadsheet it can be as easy as using the TRANSPOSE function on a range to transform the rows and columns into columns and rows, but how do you do that in Python? To transpose a list of lists in Python first flatten the two-dimensional list into a one-dimensional list then use the following: [flat_list[e::len(list_2d[0])] for e in range(len(list_2d[0]))] where flat_list represents the flattened list, and list_2d represents the original 2D list. ...

October 22, 2021 · 6 min · 1210 words · Ryan Sheehy

How To Create A List With Values: Python Code (Examples, One-Liners, No Imports)

You can construct a list in a certain number of ways as detailed in the Python documentation. The most popular I use the most is by defining my list variables using the [] list square bracket notation, for example as my_list = []. This works well when you want to start a list empty, but what if you want to be able to start with a list so that it is prepopulated with values? ...

October 13, 2021 · 4 min · 850 words · Ryan Sheehy