"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"st='Hello World'\n",
"print 'The line is :'\n",
"print st"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"The line is :\n",
"Hello World\n"
]
}
],
"prompt_number": 5
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
Example 10.6, Page Number: 10.5
"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"\n",
"strin='Welcome to python'\n",
"for i in strin:\n",
" print i,"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"W e l c o m e t o p y t h o n\n"
]
}
],
"prompt_number": 6
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
Example 10.7, Page Number: 10.6
"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"\n",
"str1='Programming'\n",
"len1=len(str1)\n",
"print 'The length of the string is ',len1\n",
"\n",
"str2=str1\n",
"print 'First string is %s and copied string is %s' %(str1,str2)\n",
"\n",
"str3='Computer'\n",
"\n",
"if str1==str3:\n",
" print 'Both strings are equal'\n",
"elif str1Example 10.8,Page Number: 10.7
"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"def strlength(str1):\n",
" count=0\n",
" for i in str1:\n",
" count+=1\n",
" \n",
" return count\n",
"def strcopy(src):\n",
" dst=[]\n",
" for i in src:\n",
" dst.append(i)\n",
" \n",
" dst=''.join(dst)\n",
" \n",
" return dst\n",
"\n",
"\n",
"str1='New Delhi'\n",
"len1=strlength(str1)\n",
"print 'The length of the string is ',len1\n",
"\n",
"str2=strcopy(str1)\n",
"print 'First string is %s and copied string is %s' %(str1,str2)\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"The length of the string is 9\n",
"First string is New Delhi and copied string is New Delhi\n"
]
}
],
"prompt_number": 8
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"def leftconcat(dst,src):\n",
" dst=src+dst\n",
" return dst\n",
"\n",
"def rightconcat(dst,src):\n",
" dst=dst+src\n",
" return dst\n",
"\n",
"str1='Hello'\n",
"str2='Friends'\n",
"\n",
"tempstr=leftconcat(str2,str1)\n",
"print 'The first string after left concatenation becomes ', tempstr\n",
"\n",
"tempstr=rightconcat(str2,str1)\n",
"print 'The first string after right concatenation becomes', tempstr\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"The first string after left concatenation becomes HelloFriends\n",
"The first string after right concatenation becomes FriendsHello\n"
]
}
],
"prompt_number": 10
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
Example 10.11,Page Numbr: 10.12
"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"\n",
"str1='All good boys have bread'\n",
"count=0\n",
"\n",
"for i in str1:\n",
" if i=='a' or i=='e'or i=='i' or i=='o' or i=='u' or i=='A' or i=='E' or i=='I' or i=='O' or i=='U' :\n",
" count+=1\n",
" \n",
"print 'Total number of vowels in a given text are ',count"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Total number of vowels in a given text are 8\n"
]
}
],
"prompt_number": 11
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"