Home » Search results for 'python string'

Python NumPy Crash Course – A Simple Tutorial and Example

Python Numpy Course Tutorial Example

Python’s NumPy library is the standard for working with numerical data. This article will explain why that is, and how to use it. In addition to this, code examples for basic usage will be shown, and we will build a real-world example that implements NumPy to work with some example data. Python and Arrays Whether you are working with data collected for scientific or business reasons, it is usually collected in the form of arrays of data presented as tables with single or multiple columns. … Read more

Home » Search results for 'python string'

Printing Text in Python Without a Newline

Python print without newline

This short tutorial will show you how to print text in Python, without a new line appearing. The Newline Character in Python In Python, newlines are represented by a \ (backslash) followed by n: \n You Can Add New Lines to Printed Strings The \n won’t be shown to the user – a new line will be inserted instead (unless an escape character is added). So, when the below code is executed: print(“Linux\nScrew”) It will appear as: Linux Screw Print Statements Add a Newline By Default By default, a newline … Read more

Home » Search results for 'python string'

How to Read CSV Files in Python, With Examples

Python read from csv file

This article will show you how to read CSV (Comma Separated Values) files in the Python programming language, with examples. What is CSV (Comma Separated Values) CSV (Comma Separated Values) is a format for storing and transmitting data, usually in a text file, in which the individual values are separated by a comma (,). Each row in a CSV file represents an individual record containing multiple comma separated values. A CSV file looks like this: name,age,favourite colour Fred,54,green Mary,31,pink Steve,12,orange Above, the CSV describes three people, with information … Read more

Home » Search results for 'python string'

How to Sort a Dictionary by Value in Python [Examples]

Python sort dictionary by value

This article will show you how to sort a dictionary by the values it contains in the Python programming language. Code examples are included. What is a Dictionary? A dictionary is one of Pythons built in variable types for storing data. Dictionaries are similar to associative arrays or hash tables in other languages. A dictionary contains a collection of values or objects. Unlike lists and arrays, rather than their values being stored at a specific index (the ordered position in the sequence of stored values), values in a dictionary … Read more

Home » Search results for 'python string'

How to Calculate Natural Logs/Logarithms (ln) in Python

Python calculate natural log:logarithm

This article will show you how to calculate natural logs/logarithms in the Python programming language, with examples. What is a Natural Log/Logarithm (ln)? A number’s natural logarithm is it’s logarithm to the base of e. It’s a bit more advanced than the usual arithmetic you’re probably used to seeing as you learn to program, so here’s a bit of explanation: A logarithm is the reverse of an exponent. The logarithm of a number is the exponent that another number must be raised to to produce the first number. You’re … Read more

Home » Search results for 'python string'

How to use the Python sum() Function to Add/Sum Numbers

Python sum

The Python sum() function takes a list of numbers, and sums them up (totals/adds them all together). Here’s how to use it, with examples. Summing/Totalling/Adding Numbers The concept of summing numbers is simple – take the numbers you wish to get the total of, and add them all together. 1 + 2 + 3 = 6 It’s basic arithmetic that you’ll use daily when writing computer software in any language. Summing Numbers in Python The sum() function in Python sums numbers. It’s a built-in function, which can be used anywhere … Read more

Home » Search results for 'python string'

How to Iterate/Loop over a Dictionary in Python [Examples]

Python iterate loop dictionary

This article will show you how to iterate/loop over the keys and values in a Python dictionary, and provide code examples. What is a Python Dictionary? In Python, a dictionary is a data type that contains a collection of objects – but unlike a list or array, rather than their values being recorded at a specific index (or ordered position in the sequence of stored values), they are stored in a key – a string identifier which both tells you what a value is for, and which … Read more

Home » Search results for 'python string'

How to Generate & Write CSV Files in Python, With Examples

Python write csv file

This article will show you how to generate CSV (Comma Separated Values) data, and write it to a file, with examples. What is CSV (Comma Separated Values) CSV (Comma Separated Values) is a format for storing and transmitting data, usually in a text file, in which the individual values are separated by a comma (,). Each row in a CSV file represents an individual record containing multiple comma separated values. A CSV file looks like this: name,age,favourite colour Fred,54,green Mary,31,pink Steve,12,orange Above, the CSV describes three people, with … Read more

Home » Search results for 'python string'

Python – Concatenating Iterators With itertools.chain() [Examples]

Concatenate:join iterables using chain in Python

This tutorial will show you how to join/concatenate/merge iterables in the Python programming language, and provide code examples. What is an ‘Iterable’ in Python? An iterable is any kind of Python object that can return each of its members one at a time. Put simply, it’s any Python object that contains multiple values that can be looped over. Python’s built-in Iterables include lists, strings, and tuples — all object types which can be represented as a sequence of values. Iterating over Iterables To demonstrate this behaviour, we can create a list of strings, … Read more

Home » Search results for 'python string'

Running External Programs in Python with subprocess [Examples]

Python subprocess

This article will show you how to use the Python subprocess module to run external programs and scripts from Python. It is often necessary to call external applications from Python. Usually these are command-line applications which you can use to perform tasks outside of the Python environment, like manipulating files, or interacting with third party services. For example, you might call the wget command to retrieve a remote file. Any application which is accessible on the command line is available to subprocess, and can be executed from within Python. You … Read more