0% found this document useful (0 votes)
29 views

Python General and Specifc Notes

The document discusses Python concepts covered on Day 1 including: 1. Printing - Using print() to output text in the console. Strings must be enclosed in either single or double quotes. 2. String manipulation - Methods like \n for new lines and string concatenation + to join strings without spaces. Spaces can be added to strings. 3. Debugging - Finding and correcting errors like unexpected parentheses. 4. Commenting - Using # for single line comments and ''' for multi-line comments. 5. Variables - Assigning information to variables to reference later in code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Python General and Specifc Notes

The document discusses Python concepts covered on Day 1 including: 1. Printing - Using print() to output text in the console. Strings must be enclosed in either single or double quotes. 2. String manipulation - Methods like \n for new lines and string concatenation + to join strings without spaces. Spaces can be added to strings. 3. Debugging - Finding and correcting errors like unexpected parentheses. 4. Commenting - Using # for single line comments and ''' for multi-line comments. 5. Variables - Assigning information to variables to reference later in code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

#Day 1(Printing,commenting,debugging,string manipulation,varaibles)

(Python notes)
1.printing: a code that simply prints what is written inside the
parentheses and output it in the console.

#General formula/Print(). #the code(print) is all in lower case


letters
✔ General notes/if you want to print a text in python you should

simply put two quotations inside the parentheses .

$this type of info(a text) in python language is called a string.


$ it has to be placed between to sets of quotations like this(“”)or
this(‘’).
$this info is not a code.

!if you forgot one of the quotations you will get the error message
That says{syntax error}when you run your piece of code.

make line of code that when it is excuted the


program Output these exact lines;
Day 1 - Python Print Function
The function is declared like this:
print(‘what to print’)
print(“Day 1 - Python Print Function”)
print(“The function is declared like this:”)
Print(“ print(‘what to print’) “)

#we changed the double quotes to single quoates of the string for a reason and that is if we didn’t do that the
program would give us an error message because it would read it this way:

Print(“ Print(“What to Print” ) ” )


String Code String
#Day 1(String manipulation) *spaces site.

2.String manipulation/there are many ways to manipulate the


“string” info type one of which is{we will arrange them in letters
starting from;}:
A.back slash and n ( \n): This allows as to print multiple strings
In different lines as long as!;

#the strings are separated by the (\n).


#within the same quotations.

Good to note;unless you want the console to print the string after
the(\n)with a space behind it you don’t want to press the space
button after the (\n).(tldr,don’t press space)

Ex/print(“hello\ndear\nbrother”)———>gives..hello
dear
brother
B.string concatenation(+):as the name suggests,it combine two
strings into one without spaces between the strings.
Ex/Print(“hello”+”world”)——>gives..helloworld
Good to note;to seprate two strings you can add spaces. there is 3
ways;

1.add the space to the end of first string Like this print(“hello “+”world”)
2.to the beginning of the first stringLike this print(“hello”+” world”)
3.add a space in the form of another string by
adding another (+) Like this print(“hello”+” “+”world”)
Space in the form of a string

!Spaces are important in python(not the spaces inside the strings)


But those that are within the code lines,So if you add a spcace
behind the (print)code you’ll get an {Indentation error!}.
#Day 1(Debugging,commenting)

3.debugging /is simply to correct an error within the code or


ironically a”bug” so the code returns to working normally.

!if you have an extra open parentheses you’ll get the error message
{syntax error;unexpected error while parsing}it simply means that
The computer would still expect you to continue then close the
statement.

*You can comment in python using two ways

# using the (#)before one line of comment


# using ‘’’ before and after multiple lines
#Day1(Variables)

4.variables/ this code assignes an info to a codeline(Varaible)so we


can use this info by refering to the variable name
#Day 1
#Day 1
(Python notes)
✔ General notes/*multiple function can be placed in single line
of code(so multiple function can be used together)

make a programme that calculates the lenth of


any name you input(avoid printing anything
except the lenth)
If you wrote the first line

2 ways
As input(“”) then assigned this line to
a variable
If you just put
Varaible=input

1.My_name = Input(“input the name”)


The programmecwill return the
message<abuilt-in function>
This can be avoided and should
always be remmbered as functions
always has to have a set of parenthesis
after them

Print(len(My_name))or
My_name=input(“the name”)
Lenght=len(My_name)
Print(length)
2. Input(“your name is:”)
Len(input(“your name”)
Print(len(input(“your name”) *this is the line of code we write in the shell
The above lines is to demonstrate how python is
reading and excuting the code

You might also like