0% found this document useful (0 votes)
6 views2 pages

Lec 6

The document discusses different types of operators including unary, binary, ternary and concatenation. It provides examples of using operators like addition, repetition and comparison on strings. It also explains type errors and string comparison and the use of new line characters.

Uploaded by

mr.x2020jindahai
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)
6 views2 pages

Lec 6

The document discusses different types of operators including unary, binary, ternary and concatenation. It provides examples of using operators like addition, repetition and comparison on strings. It also explains type errors and string comparison and the use of new line characters.

Uploaded by

mr.x2020jindahai
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/ 2

Operators

Unary opeartor : one operand

Binary operator : two operands

Ternary operator : three operands

Precedence Table for reference

Concatenation operator

In [6]: 1 # string + string


2
3 "Keshav" + "Mahavidyalaya"

Out[6]: 'KeshavMahavidyalaya'

Repetition Operator

In [7]: 1 "Keshav" * 4

Out[7]: 'KeshavKeshavKeshavKeshav'
In [8]: 1 # Type Error
2 "Keshav" + 2

--------------------------------------------------------------------------
-
TypeError Traceback (most recent call las
t)
Cell In[8], line 1
----> 1 "Keshav" + 2

TypeError: can only concatenate str (not "int") to str

In [9]: 1 "Amit" > "amit"

Out[9]: False

In [11]: 1 "amit" > "Amit"

Out[11]: True

In [13]: 1 ord("A")

Out[13]: 65

In [14]: 1 ord("a")

Out[14]: 97

new line character /n

In [18]: 1 print("it's a new line\nit's a new line") # notice the use of single and doubl

it's a new line


it's a new line

You might also like