Author: admin
-
Python Booleans
Boolean Values In programming you often need to know if an expression is True or False. You can evaluate any expression in Python, and get one of two answers, True or False. When you compare two values, the expression is evaluated and Python returns the Boolean answer: ExampleGet your own Python Server When you run a condition in an if statement,…
-
Python Strings
Strings Strings in python are surrounded by either single quotation marks, or double quotation marks. ‘hello’ is the same as “hello”. You can display a string literal with the print() function: ExampleGet your own Python Server Assign String to a Variable Assigning a string to a variable is done with the variable name followed by an equal sign and…
-
Python Casting
Specify a Variable Type There may be times when you want to specify a type on to a variable. This can be done with casting. Python is an object-orientated language, and as such it uses classes to define data types, including its primitive types. Casting in python is therefore done using constructor functions: ExampleGet your…
-
Python Numbers
Python Numbers There are three numeric types in Python: Variables of numeric types are created when you assign a value to them: ExampleGet your own Python Server To verify the type of any object in Python, use the type() function: Example Int Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.…
-
Python Data Types
Built-in Data Types In programming, data type is an important concept. Variables can store data of different types, and different types can do different things. Python has the following data types built-in by default, in these categories: Text Type: str Numeric Types: int, float, complex Sequence Types: list, tuple, range Mapping Type: dict Set Types: set, frozenset Boolean Type: bool…
-
Python Variables
Creating Variables Python has no command for declaring a variable. A variable is created the moment you first assign a value to it. ExampleGet your own Python Server Variables do not need to be declared with any particular type, and can even change type after they have been set. Example Casting If you want to specify…
-
Python Comments
Creating a Comment Comments starts with a #, and Python will ignore them: ExampleGet your own Python Server Comments can be placed at the end of a line, and Python will ignore the rest of the line: Example A comment does not have to be text that explains the code, it can also be used to…
-
Python Syntax
Execute Python Syntax As we learned in the previous page, Python syntax can be executed by writing directly in the Command Line: On this page Execute Python SyntaxPython IndentationPython VariablesPython CommentsExercises Or by creating a python file on the server, using the .py file extension, and running it in the Command Line: Python Indentation Indentation…
-
Python Getting Started
Python Install Many PCs and Macs will have python already installed. To check if you have python installed on a Windows PC, search in the start bar for Python or run the following on the Command Line (cmd.exe): To check if you have python installed on a Linux or Mac, then on linux open the…
-
Python Introduction
What is Python? Python is a popular programming language. It was created by Guido van Rossum, and released in 1991. It is used for: What can Python do? Why Python? Good to know Python Syntax compared to other programming languages ExampleGet your own Python Server