Getting Started

  • Example: Fahrenheit to Celsius in Python

    Now we can look at a useful complete simple program in Python. This program asks the user to enter a temperature in Fahrenheit and converts it to a temperature in Celsius. If you’re new to programming, it’s well worth typing it out, getting it working, and then trying to write your own similar program, for…

    Read more

  • Casting and Conversion

    In Python, and in most programming languages, the value 123 is a very different thing to the string “123” The first is a number that you can use in calculations. The second is some text: you can’t use it in calculations. A common thing to do is convert text representing a number to an actual…

    Read more

  • Formatting Strings

    A very common thing to want to do in Python is to create a string that has the values of variables embedded in it. The easiest way to do this is to use Python f-strings. The string is prefixed with a lowercase or uppercase ‘F’ and then variables can be placed in the string, surrounded…

    Read more

  • Python Types

    In Python, unlike in many other programming languages, variables do not have a type. This means that, for example, you could make a variable refer to a string, then later on make the same variable refer to a number instead. A Python variable is really just a name to attach to a piece of data.…

    Read more

  • Getting User Input

    We’ve been using the print function to print text, like this: Functions are named blocks of code that achieve a particular task. In this case, we are running the print function, which outputs text to the console or terminal. We have passed the string “Hello” to the function; things that we pass to functions are…

    Read more

  • Python Strings

    In programming, a “string” means a sequence of characters; in other words, some text. Short pieces of text in Python are defined by enclosing them in double or single quotes (it doesn’t matter which; there’s no difference). We can then assign the text to a variable, so we can refer to it later. Multi-line Strings…

    Read more

  • Arithmetical Operators

    We can use the following operators to do calculations in Python: +, -, *, /, //, %, ** You can use variables that refer to numbers and literal numbers interchangeably when doing calculations. You can also use brackets () to make expressions easier to read. Examples If you’re new to programming, it’s best to start…

    Read more

  • Python Print

    Now we can create our first “hello world” Python program. Save the following text to a file called hello.py Run the program (ideally using a Python virtual environment) in your console. Output multiple arguments separated by spaces: We can supply multiple arguments to the print function. The arguments will all be printed, separated by spaces.…

    Read more

  • Python Virtual Environments

    Python virtual environments make it easy to work with multiple versions of Python on the same machine. It’s recommended that you always use a virtual environment to run your code, so that you’re always using the correct version of Python. Creating a Python Virtual Environment If this doesn’t give you the correct version, you need…

    Read more

  • Introduction

    In this free online course you’ll learn how to write Python programs and use powerful machine learning (artificial intelligence) techniques in your code. To get started, you’ll need two things: Install Python If you’re using Windows, you may be able to install Python just by typing ‘python’ in the Windows console. If you’re using Mac…

    Read more

Blog at WordPress.com.