This document provides an overview of key concepts in Python including data types (strings, integers, floats), expressions, variables, comments, conditional statements, and loop structures. It defines each concept and provides examples. The key topics covered are data representation using variables, writing readable code through comments, and controlling program flow using conditional statements and loops.
This document provides an overview of key concepts in Python including data types (strings, integers, floats), expressions, variables, comments, conditional statements, and loop structures. It defines each concept and provides examples. The key topics covered are data representation using variables, writing readable code through comments, and controlling program flow using conditional statements and loops.
This document provides an overview of key concepts in Python including data types (strings, integers, floats), expressions, variables, comments, conditional statements, and loop structures. It defines each concept and provides examples. The key topics covered are data representation using variables, writing readable code through comments, and controlling program flow using conditional statements and loops.
kind of data a value represents. Specifically there are three different data types that you need to be aware of at this time namely :- Strings Integer floats Cont. • STRING : is a text consisting of zero ( empty string ) or characters.
• Integers are whole numbers, which can be
positive or negative.
• Floats, or “floating-point numbers,” are
numbers with decimals. expression • An expression : is a combination of one or more values (such as String, integer, or floats) using operators, which result in a new value. • The value on the right and left of the + operator is called operands. Variables • Programs usually store data in the computer’s memory and perform operations on that data. • Programs use variables to access and manipulate data that is stored in memory. • A variable is a name that represents a value in the computer’s memory. Cont.
• For example : a program that calculates the
distance between two cities might use the variable name Distance to represent that value in memory. Variable name • when you create variables , you are free to choose the names of variables as you like , provided that you follow a few simple rules namely: • A variable name must consist of only letters , digits and or underscore (_) • A variable name must start with a letter or an underscore. • A variable name should not be a reserved word. Comments in python • When writing code in python , it is important to make sure that your code can be easily understood by others. • Awesome and easy way to increase the readability of your code is by using comment. • Comments are short notes placed in different parts of a program, explaining how those parts of the program work. Cont. • Although comments are a crucial part of a program , comments are intended for a person reading a program’s code , not the computer. • To write a comment in python , simply put the hash mark # before your desired comment. • When the python interpreter sees a # character , it ignores everything from that character to the end of the lines. • This line is an example of comment : #this is a comment. Conditional statements • you have mostly viewed computer programs as sequence of instruction that are followed one after the other. • Sequencing is a fundamental concept of programming ,but it alone is not sufficient to solve every problem. • Often it is necessary to alter the sequential flow of a program to suit the needs of a particular situation. • To do that is used control structures. Cont.
• A control structure are an essential part of
programing that allow you to specify the flow of execution in your code. Loop structures for repetitions
• Computers are often used to automate
repetitive tasks. • Repeating similar tasks without making error is something that computers do well and people do poorly. Cont.
• Each execution of the body of a loop is known
as an iteration. • If loop does not have a way of stopping it is called an infinite loop END